[CentOS] sed

Fri May 23 16:59:24 UTC 2008
Thomas Johansson <thomasj at isy.liu.se>


Stephen Harris wrote:
> On Fri, May 23, 2008 at 06:02:29PM +0200, Mihai T. Lazarescu wrote:
>   
>> On Fri, May 23, 2008 at 08:41:19AM -0700, Scott McClanahan wrote:
>>     
>>> 1.1.1.1    foo
>>> 10.10.10.10    bar bar2
>>> 100.100.100.100    foobar foobar2 foobar3
>>>       
>
>   
>>> == After ==
>>>       
>
>   
>>> 1.1.1.1    foo.contoso.com
>>> 10.10.10.10    bar.contoso.com bar2
>>> 100.100.100.100    foobar.contoso.com foobar2 foobar3
>>>  
>>> Any advice on how to pull this off?  Thanks.
>>>       
>> sed 's/ /.contoso.com '
>>     
>
> That works because we've explicity been told
>   <ip address> <tab> <short hostname> <space> <short hostname alias>
> so the first space is a good place to switch.
>
> More generally, if there's possibly multiple spaces or tabs in multiple
> places this might work:
>
>   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/'