[CentOS] sed
Stephen Harris
lists at spuddy.org
Fri May 23 16:38:39 UTC 2008
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 [ ] )
--
rgds
Stephen
More information about the CentOS
mailing list