我想创建一个脚本来注释掉我的 Mac OS X 主机文件中包含.com
. 还有一个可以扭转它。
所以这:
127.0.0.1 foo.com
127.0.0.1 bar.com
127.0.0.1 baz
127.0.0.1 qux
会成为:
#127.0.0.1 foo.com
#127.0.0.1 bar.com
127.0.0.1 baz
127.0.0.1 qux
我在 Google 和 sed 手册页上环顾四周,并用 bash 和 sed 尝试了一些东西,但我还没有接近。
sed 's/^/^#/' | grep '.com' < hosts
grep '.com' | sed 's/^/^#/' < hosts
感谢您的任何帮助!