Just a small note: the script could be writen more consisley (and maybe in a more understandable way) by doing:
/baz
t
s/baz/elephants
wq
Writing .t. is like running vi ./file instead of vi file in a shell. And ed allows you to write and quit in the same command, just like :wq does in vi.
While I would have personally chosed emacs to do this task (using dired + keyboads marcos would be quite straightforward), I do agree that ed(1) is a quite helpfull and underestimated tool, especially when you embed it into a shell script with a here-doc. And despite apperances, it really isn’t that complicated, especially when you have a good man page (eg. OpenBSD’s) or have GNU Info + the ed manual installed, in case one needs to do something more esoteric.
And despite apperances, it really isn’t that complicated
UNIX V7 actually shipped interactive tutorials to learn ed(1) as part of learn. It’s unfortunate that there’s no convenient way to actually make use of those. You’d actually have to set up a PDP-11 emulator with V7 (though prebuilt images exist) and work with that, an environment where backspace doesn’t really work out of the box.
I’m a pretty mediocre emacs user, and poking around at the manual, I wasn’t qutie sure how to use dired to apply a macro to multiple files. I guess if you had a dired buffer with just the files you wanted, you could write the macro to open the file, do the operation, return to the dired buffer, then go on. Is that the idea?
While I’m no expert, that would have been what I would was thinking about. And despite first appearances, I don’t even think there’s anything too wrong about it either. I guess if you really wanted to be “save” you could write a script that processes all buffers on a stack by applying a function or a marco within them, but I don’t see the practical advantage. Whenever I did “start a macro in dired, open a file, edit it, close, move to next line (manually or via C-s)”, I didn’t have any problems with the method.
Just a small note: the script could be writen more consisley (and maybe in a more understandable way) by doing:
Writing
.t.is like runningvi ./fileinstead ofvi filein a shell. And ed allows you to write and quit in the same command, just like:wqdoes in vi.While I would have personally chosed emacs to do this task (using dired + keyboads marcos would be quite straightforward), I do agree that
ed(1)is a quite helpfull and underestimated tool, especially when you embed it into a shell script with a here-doc. And despite apperances, it really isn’t that complicated, especially when you have a good man page (eg. OpenBSD’s) or have GNU Info + the ed manual installed, in case one needs to do something more esoteric.UNIX V7 actually shipped interactive tutorials to learn ed(1) as part of learn. It’s unfortunate that there’s no convenient way to actually make use of those. You’d actually have to set up a PDP-11 emulator with V7 (though prebuilt images exist) and work with that, an environment where backspace doesn’t really work out of the box.
I’m a pretty mediocre emacs user, and poking around at the manual, I wasn’t qutie sure how to use dired to apply a macro to multiple files. I guess if you had a dired buffer with just the files you wanted, you could write the macro to open the file, do the operation, return to the dired buffer, then go on. Is that the idea?
While I’m no expert, that would have been what I would was thinking about. And despite first appearances, I don’t even think there’s anything too wrong about it either. I guess if you really wanted to be “save” you could write a script that processes all buffers on a stack by applying a function or a marco within them, but I don’t see the practical advantage. Whenever I did “start a macro in dired, open a file, edit it, close, move to next line (manually or via
C-s)”, I didn’t have any problems with the method.