Batch Editing Files with ed

255

The other day at work I needed to edit 200 files at once. I wanted to do something pretty simple: basically, I had files that looked like this:

foo:
  - bar
  - baz
  - bananas

and I wanted to insert an extra line after the baz line that said elephant

foo:
  - bar
  - baz
  - elephant
  - bananas

I had one extra weird requirement which was that some of the lines were indented with 2 spaces, and some with 4 spaces. The - elephant line needed to have the same indentation as the previous line.

Read more at Julia Evans