Given a long list of upper-case words (one word per line), such as:
MARY JOE SCOTT FRED ... (for thousands of rows) ...
You want to change this to
Mary Joe Scott Fred (etc)
Use perl from the command line. Assume all your names are in a file called ‘names.txt’. We’re going to send the output to a new file called ‘cap_names.txt’.
$ perl -pe 's/^(.)(.*)$/\1\L\2/g' names.txt > cap_names.txt
How this works
On the matching side:
^(.) → get the first character. The parenthesis allow us to refer to it as
(.*)$ → get the rest of the line. The parenthesis allow us to refer to it as
On the substitution side:
\1 → outputs that first character, as is.
\L\2 → outputs everything else, lower case (the
\L makes everything in
\2 lower case).
Inspired by Regexident’s answer at StackOverflow.
August 9, 2012 Thursday at 4:02 pm