Reputation: 559
I have a file.
My second line begins with a '#' symbol.
Which command should I use to remove that symbol?
Also on the third line, I have to put a '#' symbol at the beginning of the line.
For example:
line 2: # url: http//192.168.1.1:8000
line 3: url: http//example.com
when running the command, change the place of that '#'
Alternativly, is there a way to put the local IP in second line automatically? (So if I restart the router for example, the line will refresh the IP)
Upvotes: 1
Views: 1313
Reputation: 242028
You can use sed
:
sed -i~ '2 s/^#//' filename
-i~
will create a backup2
is the line number where the next command will be applieds/ pattern / replacement /
is a substitution. Here, we substitute with nothing.^
in a pattern matches the start of a line.To remove the octothorpe from the second line and add it to the third one, use
sed -i~ '2 s/^#//; 3 s/^/#/' filename
Upvotes: 1