echo -e '/-baz\n+1\ni\n-elephant\n.\nw\nq\n'|ed foo
for speed, put $TMPDIR on memory file system
sed requires no temp file
1.sed: /-baz/a\ -elephant sed -f 1.sed foo|sed -a wfoo
1.sed: s/- baz/- elephant/; /^ - elephant/{h;G;} /^ - elephant/{h;G;} s/- elephant/- baz/; sed -f 1.sed foo|sed -a wfoo
1.sed: /^ - baz/a\ - elephant /^ - baz/a\ - elephant sed -f 1.sed foo|sed -a wfoo
for speed, put $TMPDIR on memory file system
sed requires no temp file
works with all versions of sed, e.g., not all versions support "\n" in patterns nor so-called "edit-in-place" automatic temp file creation and removal