in reply to Re: Case Munging
in thread Case Munging

It just occurs to me that you said the file holds the names in upper cases (my previous post assumed lower-case).

So use this instead:

perl -i.old -pe 's/(?<=[A-Z])(\w)/lc $1/eg' <FILENAME>
And the regex contains a (this time positive) lookbehind-assertion (and not lookahead as I wrote above).

Sorry for the confusion.

Replies are listed 'Best First'.
Re^3: Case Munging
by AnomalousMonk (Archbishop) on Apr 17, 2009 at 02:16 UTC
    FWIW, the following may give a slight improvement in speed, simplicity or generality (I will not bother to put it into file-processing form):
    >perl -wMstrict -le "for (@ARGV) { s{ (?<= [[:upper:]]) ([[:upper:]]+) }{\L$1}xmsg; print; } " "XYZZY" "RUN4LIFE" "RUN42LIFE CO" "GENERAL WIDGET CO., INTL" "MI-GO BRAIN CYLINDERS, IPTY." Xyzzy Run4Life Run42Life Co General Widget Co., Intl Mi-Go Brain Cylinders, Ipty.
    Supposed advantages:
    • The  ([[:upper:]]+) quantified capture grabs as much as possible of whatever is to be lower-cased (rather than capturing a character at a time);
    • The use of the  \L interpolation modifier eliminates the need for evaluation in the regex (i.e., no  //e regex modifier);
    • The use of  [[:upper:]] and  \L bring locale fully into play (I think).
Re^3: Case Munging
by mikeraz (Friar) on Apr 17, 2009 at 02:38 UTC
    Good clarification for the archives. I'd mentally prefaced `lc <INPUT>` since that was a necessary step to get to the end state.
    Be Appropriate && Follow Your Curiosity