Ed

HomePage | Recent changes | View source | Discuss this page | Page history | Log in |

Printable version | Disclaimers | Privacy policy

ed is the text editor originally specified as the standard on the UNIX operating system. It was influenced by an earlier editor known as qed, and went on to influence ex which itself spawned vi.

In current practice it is almost never used interactively but does find use in some shell scripts. For interactive use ed has largley been subsumed by the de facto standard vi editor, although this is certainly not universal.

The syntax of ed influenced many UNIX tools such as sed, awk, and grep, and through them the Perl programming language.

ed has almost no visual feedback, and is famous for its terseness. For example it does not show you the current filename, or even line number, unless you ask it to. The message that ed will print in case of error, or when it wants to make sure you want to quit without saving is "?". ed's briefness was extremely useful to save resources when the output device was a line printer. It is also usable over a very slow link, and takes little space on hard disk or in the computer's memory. Most of these advantages are of little relevance after the 1980s.

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

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 aplly 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". q will end our ed session.