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.
sed '/\.com/s/^/#/' < hosts
Interpretation:
/\.com/
- only perform the rest of the command on lines matching this regexs/^/#/
- insert #
at the beginning of the lineIf you want to replace the original file, use sed's -i
option:
sed -i.bak '/\.com/s/^/#/' hosts
This will rename hosts
to hosts.bak
and create a new hosts
with the updated contents.
To undo it, use:
sed -i.bak '/^#.*\.com/s/^#//' hosts