p.s. beware of things already containing quotes, apostrophies, and backtics - many people enjoy putting their names into web forms by typing things like:-
joe `rm -rf .` smith
and so on - which of course will erase your entire PC if you run it through any script without noticing :-)
Also - there's a difference between " and ' under unix: you probably meant ' and not " earlier - do this to see why:-
echo "fred $HOME"
or
echo "fred `ls`"
Main Topics
Browse All Topics





by: ChrisDrakePosted on 2004-11-29 at 02:32:59ID: 12694658
You probably want to use perl (specifically - "perl -e") ? It's considerably more powerful, and understands all alphabets in all languages, instead of just English using ASCII
echo 'fred nerk' | perl -e 'undef $/;$a=<>; $a=~s/\b(.)/\u$1/sg; print $a';
What the above does is...
undef $/; # treats line breaks like spaces, instead of input terminators
$a=<>; # Gets the input
$a=~s/\b(.)/\u$1/sg; # Does the conversion*
print $a; # Outputs it
Here's the regular expression explanation:-
$a # This has out input
=~ # Tells perl to convert it using the following regexp
s/ # Says we want to substiture stuff
\b(.) # Matches any "word break" and grabs the next character
/ # End of the match separator
\u$1 # replaces what we matched with the uppercase version of it ($1 is the variable from the earlier matching brackets)
/sg; # "s" means treat line breaks like spaces, "g" means do everything (not just the 1st)