-->

sed memo: output boilerplate around each line in a file

Oct 03, 2011

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.

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

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.