I'd like to create a script to comment out lines of my Mac OS X hosts file that contain .com
. And also one to reverse it.
So this:
127.0.0.1 foo.com
127.0.0.1 bar.com
127.0.0.1 baz
127.0.0.1 qux
would become:
#127.0.0.1 foo.com
#127.0.0.1 bar.com
127.0.0.1 baz
127.0.0.1 qux
I looked around on Google and the sed man page and tried a few things with bash and sed, but I haven't come close.
sed 's/^/^#/' | grep '.com' < hosts
grep '.com' | sed 's/^/^#/' < hosts
Thank you for any help!