[CentOS] sed
Matt Shields
mattboston at gmail.com
Fri May 23 15:50:15 UTC 2008
On Fri, May 23, 2008 at 11:41 AM, Scott McClanahan
<SMcClanahan at forterrainc.com> wrote:
> Not specific to CentOS but I know you guys would be really helpful anyhow.
> Basically, I have a file which has been editted in the past very similarly
> to the hosts file only now I want to use it as a hosts file and need to run
> some fancy sed to massage the data into shape. Currently, the data in the
> file is in the form of <ip address> <tab> <short hostname> <space> <short
> hostname alias>. In some cases there may not be any aliases so the end of
> line would be right after the short hostname (no space at the end either).
> In other cases there could be many space separated short hostname aliases.
> What I have been trying to do without success is add our domain name to the
> first string after the ip address and tab character. As an example,
>
> == Before ==
>
> 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.
I'd use awk. Put the lines in a file, then do this
cat test.txt | awk '{ print $1 "\t" $2 ".centos.com\t" $3 "\t" $4 }'
--
-matt
More information about the CentOS
mailing list