etc / hostsの行を変更する方法は?特定のドメインの行の先頭に#を追加しますか?

etc / hostsの行を変更する方法は?特定のドメインの行の先頭に#を追加しますか?

特定のホストの約15行のエントリを含むホストファイルがあります。

# Entry added by Automationこれらのすべてのホストエントリには、エントリ内にテキストがあります。

たとえば、

10.122.123.124  file1.auto.test-json.abx.com    # Entry added by Automation
10.122.123.125  file2.auto.test-json.abx.com    # Entry added by Automation
10.122.123.126  file3.auto.test-json.abx.com    # Entry added by Automation
10.122.123.127  file4.auto.test-json.abx.com    # Entry added by Automation

その行の先頭に「#」を追加するか、# Entry added by Automation行を完全に削除したいと思います。

希望の出力:

# 10.122.123.124  file1.auto.test-json.abx.com    # Entry added by Automation
# 10.122.123.125  file2.auto.test-json.abx.com    # Entry added by Automation
# 10.122.123.126  file3.auto.test-json.abx.com    # Entry added by Automation
# 10.122.123.127  file4.auto.test-json.abx.com    # Entry added by Automation

ベストアンサー1

sedでできます。

「自動化追加項目」を含む行を確認し、行の先頭を#に置き換えます。

sed '/Entry added by Automation/ s/^/# /' -i /etc/hosts

おすすめ記事