Search

The Online Encyclopedia and Dictionary

 
     
 

Encyclopedia

Dictionary

Quotes

   
 

Ed

The title given to this article is incorrect due to technical limitations. The correct title is ed.

The text editor ed was the original standard on the UNIX operating system. It was influenced by an earlier editor known as qed, and went on to influence ex, which in turn spawned vi. The non-interactive UNIX commands grep and sed were inspired by common special uses of ed; their influence is visible in the design of the programming language AWK, which in turn inspired aspects of Perl.

Famous for its terseness, ed has almost no visual feedback. For example, the message that ed will produce in case of error, or when it wants to make sure you want to quit without saving, is "?". It does not report the current filename or line number, or even display the results of a change to the text, unless requested. This terseness was appropriate in the early versions of UNIX, when consoles were teletypes, modems were slow, and hard disk and memory were precious, but these advantages ceased to apply when more interactive editors became the standards.

In current practice ed is almost never used interactively, but it does find use in some shell scripts. For interactive use, ed was subsumed by vi and Emacs editors in the 1980s. ed can be found on virtually every version of UNIX and Linux available; people who have to work with multiple versions of UNIX often know at least the basic ed commands. If something goes wrong, and the OS is somehow not fully loaded, ed is sometimes the only editor available (though the vi editor is usually available). This is often the only time when it is used interactively, aside maybe from torturing first year students.

Example session

Here is an example transcript of an ed session:

 a
 ed is the standard UNIX text editor.
 This is line number two.
 .
 2i
   
 .
 1,$l
 ed is the standard UNIX text editor.$
 $
 This is line number two.$
 3s/two/three/
 1,$l
 ed is the standard UNIX text editor.$
 $
 This is line number three.$
 w text
 65
 q

Explanation of the example

Here we started with an empty file, and used a to append text (all ed commands are single letters). That put us into insert mode, which is terminated by a singular dot on a line. The two lines that we entered before the dot end up in the file buffer. 2i goes into insert mode, and will insert the entered text (a single empty line in our case) before line two. All commands may be prefixed by a line number and will operate on that line.

In 1,$l the l stands for the list command. This time we prefixed the command by a range, two lines separated by a comma ($ means the last line). In return, ed is listing all lines, from first to last. These lines are ended with dollar signs, so that white space at the end of lines is clearly visible.

We will correct the error in line 3 with 3s/two/three/, a substitution command. The 3 will apply it to the right line, following the command is the text to be replaced, and then the replacement. Listing all lines again with 1,$l we see that the line is correct now.

w text writes the buffer to the file "text". ed responds with 65, which is the number of characters that it wrote to the file. q will end our ed session.

External links

  • UNIX Editors I http://snap.nlc.dcccd.edu/learn/nlc/ed.html
  • ed Humor http://www.gnu.org/fun/jokes/ed.msg.html




Last updated: 02-08-2005 13:06:47
Last updated: 05-03-2005 09:00:33