I have to admit that I never encountered a situation where `ed` might have been my tool of choice.
I have to admit that I never encountered a situation where `ed` might have been my tool of choice.
For a while I maintained a .html blog using only ed, just for the fun of abstaining from conveniences and learning to use an ancient program. It's somehow nice to know that it's possible.
This patch was explicitly rejected in upstream openssh as they said it could lead people to copy and paste it without considering attacks - but ignored the fact that by just telling people what file it was in, many people just deleted the file in response and those who did it right, deleting just the relevant line in cases where a key change was expected like my situation, never discovered the easier ssh-keygen -R method.
Perhaps they shouldn't offer a copy and paste solution, but mentioning that ssh-keygen is capable of it and to see the docs would be nice at least...
This assumes authenticated DNS data, of course. Not at all a given today, sadly.
kate filename:line
CTRL+K (or CTRL+D to comment out), CTRL+S, quit (current tab: CTRL+W, Alt+Tab or app: CTRL+Q)
Particularly useful when the output of the previous command (compilation for instance) already contains filename:line. Then double click, middle click paste works well.
or: kate filename
CTRL+G line <Enter>, CTRL+K, CTRL+S, quit.
`sed -i '398d' ~/.ssh/known_hosts`
I do this all the time. In fact I have a function in my .bashrc for this at work since I use it so much:
`function sedkey() { sed -i "${1}d" ~/.ssh/known_hosts }`
so I can run `sedkey 123` etc. Just another way to skin a cat I suppose.
Also, btw, you can absolutely use ed in scripts [0], but this is also something that I would pity the maintainer of.
[0] https://www.ibm.com/developerworks/community/blogs/brian/ent...
ktm5j@kurma /pool/share/pkgs $ ed ~/.ssh/known_hosts
130923
398d
wq
130755
Sed just quietly does what I want. Like I said, just another way to skin a cat, do whatever works for you.For larger things I find vi or something else of that scale more convenient. Ed just seems to fill a space between the two that I never need.
ed the_file <<< $'398d\nwq'
edit: another one liner but still using ed I guess.
ed was built for this kind of system where limited I/O was a requirement for reasonable performance. If transferring a file is too expensive, you can't wait for the system to redraw the entire screen of 25 lines and 80 columns because you scrolled past the bottom of the screen, either.
To load up a 25x80 area would give me all sorts of bad characters. Doing single lines, and find and replace made it almost feel like I was right next to the hardware.
Back in the day, it's amazing how much code one could write in these relatively primitive line-oriented editors (ed on Unix systems, editors like SOS and EDT on DEC operating systems, and so on).
E.g. the entire UNIX (including the userland).
Machines were smaller then, too. 64K of code on a PDP-11, small ROMs (hundreds of KB) for the larger embedded systems.
My belabored point: Systems were smaller. There was a lot less typing involved :-)
There are a bunch more, but nothing that really covers my early experience with Unix. Something about "common tools of the late 1970s line-oriented computing environments" might be an interesting subject, we'll see . . .
ed saved me that day.
A couple of years ago I had to boot a Debian/68k virtual machine and both vi and emacs were absent (there was joe, but at the time I wasn't aware that such editor even existed, and I wouldn't have assumed it came preinstalled anyway).
Well, ed was there.
Quite a challenge to use it because my ed-fu is weak at best, but I was able to edit the necessary files to configure networking and to be able to ssh into the machine.
I also use it in some administrative tasks, like editing dhcp.config files on BSD.
None of these happen very often.
If I have a more built-up system, I'll use mg, which is the gnu version of microEmacs.
$ uname -s; head -n 19 /usr/src/usr.bin/mg/README
OpenBSD
[This is an edited version of the original mg README, updated slightly to
reflect changes in the last 20 years.]
Mg (mg) is a Public Domain EMACS style editor. It is "broadly"
compatible with GNU Emacs, the latest creation of Richard M.
Stallman, Chief GNUisance and inventor of Emacs. GNU Emacs (and other
portions of GNU as they are released) are essentially free, (there are
handling charges for obtaining it) and so is Mg. You may never have
to learn another editor. (But probably will, at least long enough to
port Mg...) Mg was formerly named MicroGnuEmacs, the name change was
done at the request of Richard Stallman.
Mg is not associated with the GNU project, and it does not have the
copyright restrictions present in GNU Emacs. (However, some modules
do have copyright notices.) The Mg authors individually may or may
not agree with the opinions expressed by Richard Stallman in "The GNU
Manifesto".Fun fact: MicroEmacs, precursor to mg was written by David G. Conroy while at Mark Williams Company, working on the compiler to run on the DEC Rainbow.
David went on to work on the DEC Alpha, and is now at Apple.
Also, when I teach programming languages, ed is a useful enough project to start on. The editor is simple. So students can focus on language concepts for the most part, while still getting a useful software at the end (I assume regex libraries are available).
In one of them, a FreeBSD system's `/usr` and `/home` slices got corrupted, but they still had entries in `/etc/fstab`. The mount failures prevented further recovery. There were, however, a handful of binaries under `/bin`. Guess which one is really good at editing `/etc/fstab`...
ed is just one of those things I keep in the back of the toolbox that gets pulled out occasionally.
Walked him through using ed to change it. He thought it was some arcane magic.
The difference is that ed reads the entire input in memory, but it doesn't break symlinks. sed's in-place editing mode (just like perl -i or the newer awk -i inplace that is supported by GNU awk) breaks symlinks, on the other hand it can operate on arbitrarily large files.
you can also do
sed -i -e 's/a/b/' file
which will work for GNU and BSD sed.