Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sed Append Line

Tags:

linux

sed

Does sed have a command to append a line after a matched line? I tried searching around but was a bit confused with the results.

Basiclly I want it to match

#address=/doubleclick.net/127.0.0.1

And add a line below it like

#address=/doubleclick.net/127.0.0.1

address=/anotherurl/ipaddress

Is this possible?

like image 921
awmusic12635 Avatar asked Dec 27 '22 04:12

awmusic12635


1 Answers

You can use the a(append) command in sed:

$ sed -i '/^#address=\/doubleclick.net\/127.0.0.1$/a\
> address=/anotherurl/ipaddress' file.txt

Or you can use s(substitute) command:

$ sed -i 's@^#address=/doubleclick.net/127.0.0.1$@&\naddress=/anotherurl/ipaddress@' file.txt

Note: $ and > are bash prompt.

like image 158
kev Avatar answered Jan 08 '23 08:01

kev