Actually Using Ed (2012)
blog.sanctum.geek.nzEd is the standard text editor - https://www.gnu.org/fun/jokes/ed-msg.en.html
> Let's look at a typical novice's session with the mighty ed:
golem$ ed
?
help
?
?
?
quit
?
exit
?
bye
?
hello?
?
eat flaming death
?
^C
?
^C
?
^D
?If they're lucky, they'll press Q. Otherwise, ^Z will work :)
There are actually practical uses for ed in shell scripting. For example recently I had to recover my entire website from the internet archive because covid reasons it's a long story.
So I went to the internet archive, downloaded almost all of it (all of the stuff that was there), put it through lynx, to text and from there created markdown.
So at some point I had 100-ish files and I wanted to put some yaml at the top of every markdown file. While playing around with how I wanted to do this at some point I needed to make some changes. I was faced with needing to do certain simple edits in the yaml front-matter of every one of a very large number of files.
Now you could just make a vim/emacs macro and run it on every file and that would be fine, or you could use ed in a shellscript. Something like this:
find . -type f -name "*.md" | while read f ; do
ed "${f}" <<__DONE
1,^--g/^foo/d
wq
__DONE
done
So what have we achieved? We deleted lines which start with "foo" but only from the top until the first line that starts with "--". (ie in the yaml). That range address wouldn't work in sed, or not as easily. We can also do things like insert a line just after something or whatever. These are tricks that are worth learning, and everyone who does unix shellscripting should have "ed with a heredoc" in their bag of tricks.I think the second line should start with
Unless forward slashes aren't required to indicate a regex based address.1,/^--/ g...One thing I do to create my ed scripts is to actually read the output of ls with some file pattern and then use a vim macro to edit the output as follows:
The gnu info page for ed is a very good reference to determine what commands are available and how addressing works.ed <<EOF e file1 commands w e file2 commands w ... wq EOFYes you're right of course.
(2012)
Thanks, luckily caught this while I could still edit!