[CentOS] Re: sed

Sat May 24 02:48:25 UTC 2008
Les Mikesell <lesmikesell at gmail.com>

Scott Silva wrote:
>>>>>  sed 's/^\([^    ]*[     ]*[^    ]*\)\([   ]*.*\)$/\1.contoso.com\2/'
>>>>> (where there's a space *and* a TAB inside each of the [  ]  )
>>>> The above version easier to read and "copy paste". Space is space 
>>>> and tabe is \t
>>>> sed 's/^\([^ \t]*[ \t]*[^ \t]*\)\([ \t]*.*\)$/\1.contoso.com\2/'
>>> I grew up with versions of 'sed' that don't understand this new-fangled
>>> method of specifying tabs, and write enough cross-platform code that
>>> I can't rely on it (still doesn't work in Solaris 10, for example).
>> perl can do anything sed can do and has almost no platform or version 
>> related syntax differences - plus it has \s to represent 'whitespace' 
>> and you don't have to bang your head on the wall when you are half 
>> done and realize you have to do something spanning multiple lines.
> Show your example. Inquiring minds want to know!

perl -p -e 's/(\s+\S+)/$1.contoso.com /'

That's "match one or more whitespace characters followed by one or more 
  non-whitespace and add .contoso.com after whatever matched.

   Les Mikesell
     lesmikesell at gmail.com