How to search and append words in the same file using unix scripting file operations

Hi ,

I have a file myhost.txt which contains below,

127.0.0.1 localhost
1.17.1.5 atrpx958
11.17.10.11 atrpx958zone nsybhost

I need to append words only after "atrpx958" like 'myhost' and 'libhost' and not after atrpx958zone.

How to search the word atrpx958(which is hostname) only, in the file and append the words in the same file.

How can we do it using unix scripting file operations to acheive this..

Thanks in advance.

--Sree

Try this...

sed  -i 's/atrpx958$/& myhost/g' input_file

127.0.0.1 localhost
1.17.1.5 atrpx958 myhost
11.17.10.11 atrpx958zone nsybhost

--ahamed

Hi Ahamed,

I tried this, but it throws the following error
"
sed: illegal option -- i
"

Let me know,

--Sree

I suppose you are using SunOS? Well I think then you can't make the changes inline.
Try this...

sed 's/atrpx958$/& myhost/g' input_file > out_file

--ahamed

Ahamed,

Thanks for the update.
Yes, im using Sun OS.

How can this be achieved using file operations ?

-- Sree

In nawk ..

$ nawk '/atrpx958$/{print $0" myhost"}!/atrpx958$/{print $0}' infile