Actually using Ed (2012)
blog.sanctum.geek.nz
blog.sanctum.geek.nz
After 4 months, I went on a co-op term and vi was VERY nice to use if you had 4 months of intense training in regular expressions and substitution patterns using ed.
Given the computing power I have accessible now, it's like looking back on a time when people debated the speed of horses vs. how much oats they ate.
I carry in my pocket a 4 year old computer with 3 orders of magnitude more ram, storage and processing power.
bash: ed: command not found
Apparently, despite being mandated by POSIX, not every Linux distro (e.g. Arch) ship it by default> The base package does not include all tools from the live installation, so installing other packages may be necessary for a fully functional base system. In particular, consider installing:
> - userspace utilities for the management of file systems that will be used on the system,
> - utilities for accessing RAID or LVM partitions,
> - specific firmware for other devices not included in linux-firmware (e.g. sof-firmware for sound cards),
> - software necessary for networking (e.g. a network manager or DHCP client),
> - a text editor,
> - packages for accessing documentation in man and info pages: man-db, man-pages and texinfo.
[0]: https://wiki.archlinux.org/title/Installation_guide#Install_...
alias vim='emacs -nw'
alias vi='vim'
alias ed='vi'sed is most preferred, but IME there are some simple tasks that are not possible (or exceedingly difficult) with sed but possible with ed.
For example, moving lines and joining lines are obvious ones. Another is using line address "0", namely, with the "r" command.
Both sed and ed allow reading in a file after line 1 but AFAIK only ed allows inserting before line 1, at "line 0". According to the ed changelog, in 2006, the source was changed so that the "i" and "c" commands treat address 0 as address 1.
For example, a common task for me is to insert the contents of file #1 at the top of file #2.
AFAIK, this is impossible using sed's "r" command, but it's possible using ed's "r" command.
test $# -eq 2||exec echo usage: $0 srcfile dstfile
printf '0r '$1'\nw\nq\n'|ed -s $2
A less space-efficient solution, without resorting to fifos, might be something like cat $2 $1 > $1.$$.tmp;
exec mv $1.$$.tmp $1;Here is a sed solution
sed -i -e1r/dev/stdin -e1N $1
However this still has a limitation. The target file must be more than one line.Using a named pipe for large files
test -s 1.fifo||mkfifo 1.fifo
cat largefile > 1.fifo &
printf '0r 1.fifo\nw\nq\n'|ed -s $1
curl -A "" -4o 1.fifo https://example.com/largefile.gz &
gzip -dc largefile.gz|tail -100|sed -i -e 1r/dev/stdin -e1N $1 od -tx1 -An|sed 's/^/w /'|ired -n $1 /dev/stdin
Unless I am mistaken, ired does not use a temp file, unlike sed -i.https://en.wikipedia.org/wiki/TECO_(text_editor)#Example_cod...
ed is a line editor, which makes it manageable.
This distinguishes it from TECO, which is a character editor.
I find command line character editors hard to use. It's very easy to lose your place, and the cognitive load is just too high for me.
Now, mind, I never used one in anger for any real length of time. But the learning curve was off putting enough to make me seek greener pastures instead.
Like ed.
I used ed for a bit. I was using it to type in the ed clone from the Software Tools book, trying to get it to work in Turbo Pascal on CP/M (with the hope that I could get and ed to work on CP/M, because CP/Ms ed is awful).
It was quite useable and manageable. I had some rough parts, which I can't recall, but it wasn't a horrific experience to be sure.
It would take very little to make it very good:
- a quick shortcut to open the file at current line in a pager
- perhaps redesign it to work without having to hit enter after you give a command
I've started to find ed surprisingly fun to use for quick edits, I'm not leaving nvi yet but it has this nice "ancient Unix" vibe.
For me the most useful feature is the ability it has to remember the contents of regular expression matches inside \( ... \) and when you combine this with the g global edit command you can do complex manipulations in a similar way on every line in a file with a single ed line.
So
g/\(regex1\)whatever\(regex2\)/s//\2something\1/
switches whatever text matches regex1 and whatever matches regex2 and changes the intermediate text also. It's a lot to type but quite easy once you have done it a few times to write a single edit that transforms your file exactly the way you want in one go or nearly so.
However dealing with columnar data it's probably better to use something like awk.
Actually Using Ed (2012) - https://news.ycombinator.com/item?id=30318638 - Feb 2022 (7 comments)
Actually using ed (2012) - https://news.ycombinator.com/item?id=13113556 - Dec 2016 (88 comments)
Actually using Ed - https://news.ycombinator.com/item?id=4120513 - June 2012 (89 comments)
This is actually true if you ask ChatGPT to simulate a Unix session, and try editing text files. You literally can't use a visual editor.
Offending key ...
and edit the failing key out of the known_hosts file.extremely useful with bazillions of fresh virtual guests with well known static IP. you simply cut and paste the "Offending key" line into the shell and the ed script does it's magic.