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.

1 r xx00
1 !r xx02
$ !r xx01
1 d

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.