Interaction with other programsΒΆ

As ed is a traditional UNIX editor, it aims to follow the idea of doing one thing, doing it properly, and interacting with other programs. Unfortunately, and as opposed to vi, piping parts of the buffer through a command is not supported; however, it is easy to patch this behaviour in (and, in fact, I would recommend to do so).

So, without patching, the presence of more programs does not directly extend the capabilities of ed, but temporary files have to be used. Nevertheless, basic interaction is still possible (and hence, ed does get extended by a richer environment), as the e, r, and w commands interpret an expression starting with ! instead of a file name as pipes. ed does not do any processing of the command (so, all forms of redirects, like |, >, and <, can be used) except that a single % is replaced by the current file name. This expansion can be used for global operations on the file, if the contents are saved first.

Example. Sorting the whole file.

w
e !sort %

Programs you might want to look at include the following.

  • expand
  • tr
  • gzip, gunzip, zcat
  • sort (also look at the -n option)
  • your simple implementation of your favourite line-breaking algorithm