I have the following /etc/hosts file
[root@vhost41 tmp]# cat hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
119.13.248.1 ccvcds1.ihost.com vcds1
171.221.160.11 vhost.ihost.com vhost41
[root@vhost41 tmp]# echo $(ifconfig eth0 | grep "inet addr:" | cut -d ":" -f 2 | cut -d " " -f 1)
171.221.160.11
How can I use sed or awk a single line to add “AWSHOST” to the the matching ip line. So the change would be:
[root@vhost41 tmp]# cat hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
119.13.248.1 ccvcds1.ihost.com vcds1
171.221.160.11 vhost.ihost.com vhost41 AWSHOST
I tried to pipe the outputof the above command to sed and awk and it is not working. Any help greatly appreciated
1 Answer