[OT] sed command to add line after matching lines

Joe Smith jes at martnet.com
Thu Apr 23 15:14:00 UTC 2009


Dan Track wrote:
> ... I want to add a few lines after matching a couple of lines in a
> file using sed, ...

sed can be awkward when working with more than one line at a time.

Can you use perl?

$ perl -pe 'BEGIN{undef $/};s/server 10.33.45.3\nserver 
ldap.example.com\nserver orion/# server 10.33.45.3\n# server 
ldap.example.com\n# server orion\n\nserver fire.example.com\nserver 
earth.example.com\nserver space.example.com\n/s' <test.conf

(That's meant to be all on one line.)

<Joe




More information about the fedora-list mailing list