News for hackers. Stuff that matters.
Re:Batch editing files with ed by textmode on Saturday May 12, 2018 @03:20PM (#17055572)

   echo -e '/-baz\n+1\ni\n-elephant\n.\nw\nq\n'|ed foo
but ed requires a temp file in $TMPDIR to save changes

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
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
Re:Batch editing files with ed by yani on Saturday May 12, 2018 @03:41PM (#17055656)
Sure, there is more than one way to do X. It will be useful to learn why you prefer sed over ed
Re:Batch editing files with ed by bewuethr on Saturday May 12, 2018 @06:21PM (#17056314)
The sed command doesn't get the indentation right, though, as the article says it could be indented by two or four spaces.
Re:Batch editing files with ed by textmode on Saturday May 12, 2018 @06:55PM (#17056452)

   1.sed:
   s/- baz/- elephant/;
   /^  - elephant/{h;G;}
   /^    - elephant/{h;G;}
   s/- elephant/- baz/;

   sed -f 1.sed foo|sed -a wfoo
or

   1.sed:
   /^  - baz/a\
     - elephant
   

   /^    - baz/a\
       - elephant
   

   sed -f 1.sed foo|sed -a wfoo