[OT] sed command to add line after matching lines

Dan Track dan.track at gmail.com
Thu Apr 23 10:58:51 UTC 2009


Hi

I appreciate this is off-topic but I would be grateful for some help
on this. Basically,I want to add a few lines after matching a couple
of lines in a file using sed, can someone please tell me how to do
this.

Lines to match

server 10.33.45.3
server ldap.example.com
server orion

I want to comment these lines so they become:

# server 10.33.45.3
# server ldap.example.com
# server orion

Then append these lines after the commented lines

server fire.example.com
server earth.example.com
server space.example.com


So I should end up with:

# server 10.33.45.3
# server ldap.example.com
# server orion

server fire.example.com
server earth.example.com
server space.example.com

Please bear in mind there is a lot of other text in this file not just
the above and all the other text should remain untouched.

Thanks for you help in advance.
Dan




More information about the fedora-list mailing list