I want to comment out this line in /etc/hosts
:
127.0.0.1 test test
to become:
#127.0.0.1 test test
How to a one liner in bash command line to do this to find the line that just starts with 127? I am using Ubuntu 12.04.
Thanks
I want to comment out this line in /etc/hosts
:
127.0.0.1 test test
to become:
#127.0.0.1 test test
How to a one liner in bash command line to do this to find the line that just starts with 127? I am using Ubuntu 12.04.
Thanks
You can use sed(1):
sed -i '/^127/s/^/#/' /etc/hosts
-i
means to do the substitution in place, so the substitution happens in /etc/hosts
, not on stdout which is standard.
in '/^127/s/^/#/'
, '/^127/'
means find a line starting with 127 (^
is the start of line anchor), the s/^/#/
substitute the start of that line with a #
.
I think you can do this with the following command:
sed -i 's/127.0.0.1 test test/#127.0.0.1 test test/g' /etc/hosts
Try using sed
sed -i.bak 's/^127/#&/' /etc/hosts
-i.bak
- in place replace and create backup file with .bak