Unix Shell - Re: convert 1st char of a word to uppercase

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2005 > Re: convert 1st char of a word to uppercase





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: convert 1st char of a word to uppercase
John W. Krahn

2005-04-25, 5:53 pm

Michael Heiming wrote:
> In comp.unix.shell Hans Horn <hannes@2horns.com>:
>
>
> Nice thread.
>
> If you have vim you could try:
> :%s/\<\(.\)\([^ ]*\)/\u\1\L\2/g
>
> PERL might kick in handy:
> PERL -pi -e 's/([a-z]+)/\u\L$1/g' file


That won't work properly. For example it will convert 'Word' to 'WOrd' and
'utökad' to 'UtöKad' and "couldn't" to "Couldn'T". This should work better.

perl -Mlocale -pi
-e's/(?<![[:alpha:]])([[:alpha:]]+(?:['''-][[:alpha:]]+)?)(?![[:alpha:]])/\u\L\$1/g'
file


:-)

John
--
use Perl;
program
fulfillment
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com