How to search and append words in a file

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 only in the file and append the words.

Kindly let me know.

Thanks,
Sree

 
$ nawk '{if($2~/^atrpx958$/){$0=$0"TEST";print}else{print}}' inputfile
127.0.0.1 localhost
1.17.1.5 atrpx958TEST
11.17.10.11 atrpx958zone nsybhost

Adding TEST after the atrpx958

---------- Post updated at 03:50 PM ---------- Previous update was at 03:48 PM ----------

Or, you are looking for this one ?

 
$ nawk '{if($2!~/zone$/){$0=$0"TEST";print}else{print}}' inputfile
127.0.0.1 localhostTEST
1.17.1.5 atrpx958TEST
11.17.10.11 atrpx958zone nsybhost

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