Reputation: 17
How can I remove this line using scripts in bash
#net.ipv4.ip_forward = 1
Upvotes: 0
Views: 178
Reputation: 123
As I understand from the question header, you need to uncomment the network setting - then the replacing action would be, with a backup:
sed -E -i.bak 's/^#(net.ipv4.ip_forward = 1)/\1/g' your-filename
The flag -E is used to enable the back-reference feature without masking the parentheses, thanks to David C. Rankin for clarification in a comment below.
Also, the dots might be masked, but not necessary in this example thought - assuming it is being applied on a /etc/sysctl.conf and without using flag -E and mode g it will be:
$ sudo sed -i.bak 's/^#\(net\.ipv4\.ip_forward = 1\)/\1/' /etc/sysctl.conf
Upvotes: 1