Re: sed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]





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/'



_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux