Thursday, 15 April 2010

bash - Capitalize in Solaris Shell -



bash - Capitalize in Solaris Shell -

hi want capitalize variable in solaris os.

from hello_world hello_world

or hello hello

please help, solaris os:

oracle solaris 10 8/11 s10s_u10wos_17b sparc copyright (c) 1983, 2011, oracle and/or affiliates. rights reserved. assembled 23 august 2011

if have perl:

% echo hello_world foo bar | perl -pe '($_ = lc $_) =~ s/(\b|_)./\u$&/g' hello_world foo bar

perl -pe reads standard input , prints each line after applying perl code given argument. $_ current line. lc function converts string lower case. regular look matches word boundary or underscore followed character. s/// command replaces matching substring uppercase equivalent. trailing g causes replacement performed many times possible on each line (by default it's done once).

if don't have perl (i don't know whether solaris includes default), seek this:

% echo hello_world foo bar | tr a-z a-z | sed 's/\(_\|\<\)./\u&/g' hello_world foo bar

you incorporate upper-to-lower case mapping sed command using y///, unlike tr doesn't appear take ranges:

% echo hello_world foo bar | tr a-z a-z | sed 'y/abcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyz/;s/\(_\|\<\)./\u&/g' hello_world foo bar

bash shell unix solaris

No comments:

Post a Comment