sed memo: output boilerplate around each line in a file

Given three files xx0{0,1,2} the following sed script will first output the contents of file xx00 and then for each line in the input it will output xx01, the line and xx02. The substition on line 5 is optional and can be expanded to include more commands or removed completely.

1 r xx00
1 !r xx02
$ !r xx01
x
1 d
s/foo/baz/

The filenames are the default output filenames of the csplit command which could be helpful in related scenarios to the above.

Also it would be easy to add a footer to the above script, but I did not need it personally at this time.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s