/etc/hostsファイルのパターンに一致する各行の末尾に.comを追加したいと思います。
サンプルファイルの内容:
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.
私はそれが次のように見えるようにしたいです:
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
この効果を得るためのsed
コマンドはありますか?awk
ベストアンサー1
そしてawk
:
$ awk '$0 = $0 " " $NF ($NF ~ /\.$/ ? "" : ".") "com"' <file
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