[ale] sed head scratcher

fletch at phydeaux.org fletch at phydeaux.org
Wed Aug 5 14:19:45 EDT 2009


>
> cat /etc/hosts | awk '{ print $1, tolower($2), $3 }'
>

*Tweet* Useless use of cat.  Five yards and repeat the down.

awk '{ print $1, tolower($2), $3 }' /etc/hosts > hosts.new


Or the perl way . . .

perl -i.bak -lane '$F[1]=lc($F[1]);print "$F[1]\t", join( " ", @F[1..$#F]
)' /etc/hosts

> Thanks,
> Al Snow
>
>> Date: Tue, 4 Aug 2009 14:05:34 -0400
>> From: jim.kinney at gmail.com
>> To: ale at ale.org
>> Subject: [ale] sed head scratcher
>>
>> breakout the greybeards....
>>
>>
>> I have a pile of text lines that need to have a certain portion
>> transposed from upper case (windows dweebs did the hostnames) to lower
>> case.
>>
>> So many lines like:
>>
>> 192.168.0.2 MACHINE102
>> 192.168.3.4  MACHINE304 FredsBox
>> 10.0.2.3   MACHINE599  TestingSystemB
>> etc
>>
>> So varying IP address then varying spaces then upper case name with
>> digits then varying spaces and sometimes followed by other name with
>> mixed case.
>>
>> I want to ONLY lower case the names after the IP address, not anything
>> else in the line.
>>
>> Here's what I have so far:
>>
>> cat /etc/hosts | sed '/ [A-Z]{7}[0-9]{1,3}/ y/[A-Z]/[a-z]/'
>>
>> seems like it should work but it only replaces the 'A' with 'a' and it
>> does it anywhere in the line.
>>
>> So I'm pulling info from http://www.grymoire.com/Unix/Sed.html#uh-49
>> and it talks about second word in this won't work unless I use
>> multi-line editing.
>>
>> But multi-line editing makes NO SENSE in this context!!
>>
>> I could have probably already solved this problem using a different
>> method/language/beer style but at this point I'm totally geeked out on
>> this and am being stubborn.
>>
>> I appreciate any sed solutions to this.
>>
>> --
>> --
>> James P. Kinney III
>> Actively in pursuit of Life, Liberty and Happiness
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>
> _________________________________________________________________
> Express your personality in color! Preview and select themes for Hotmail®.
> http://www.windowslive-hotmail.com/LearnMore/personalize.aspx?ocid=PID23391::T:WLMTAGL:ON:WL:en-US:WM_HYGN_express:082009_______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
>


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U




More information about the Ale mailing list