« Catching up | Main | Concurrent GUI Logins »

July 14, 2005

Multi-Line sed

Lets say you want to add "disable = yes" after specific two lines in a file.

For example, the two lines:

service finger
{

The "N" command to sed tells it to read another line into the "input buffer" you can stack multiple "N"s if you need more than 2 lines.

So, the answer is:

sed -i -e N -e "s/service finger\n{/service finger\n{\n\tdisable = yes/g" /path/to/file-to-be-edited

To read 3 lines you would do something like:

sed -i -e N -e N -e N -e "s/changethis/tothis/g" /path/to/file-to-be-edited

Posted by at July 14, 2005 11:38 AM

Trackback Pings

TrackBack URL for this entry:
http://blogs.gurulabs.com/cgi-bin/mt-tb.cgi/14