3 ms·
ed is useful in one specific circumstance, but it's useful enough in that circumstance that I recommend it to anyone who's really serious about unix shell scrip
by seanhunter 3y ago
ed is useful in one specific circumstance, but it's useful enough in that circumstance that I recommend it to anyone who's really serious about unix shell scripting.
In the context of a shell script, there are things you can do with ed and a here document that are extremely difficult to do any other way. For example, I had to recover my website from the wayback machine during covid lockdown (long story).
I decided to change everything to markdown and wanted to add yaml frontmatter to every one of a hundred or so markdown files. The Yaml frontmatter needed to be different for each file and I ended up having to make various tweaks before I brought it back live.
So, ... multiple times I had to do edits like "in the fourth line above the -- that ends the yaml front matter, change x to y". This is a very tough edit to make with the usual suspects (sed/perl/awk etc), but is a breeze to do if you run ed in your shell script and have the commands you want to run supplied by a here doc.