I want to append .com at the end of line for every line matching the pattern in /etc/hosts file.
Sample file content:
127.0.0.1 localhost
1.2.3.4 hostname1 hostname1.xyz hostname1.xyz.
1.2.3.5 hostname2 hostname2.xyz hostname2.xyz.
1.2.3.6 hostname3 hostname3.xyz hostname3.xyz.
I want it to be like below:
127.0.0.1 localhost localhost.com
1.2.3.4 hostname1 hostname1.xyz hostname1.xyz. hostname1.xyz.com
1.2.3.5 hostname2 hostname2.xyz hostname2.xyz. hostname2.xyz.com
1.2.3.6 hostname3 hostname3.xyz hostname3.xyz. hostname3.xyz.com
Any sed
or awk
command to achieve this effect?
/etc/hosts
?awk '$0 = $0 " " $NF "com"' <file
should do the trick.