Ed (text Editor) - Example

Example

Here is an example transcript of an ed session. For clarity, commands and text typed by the user are in normal face, and output from ed is emphasized.

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

The end result is a simple text file containing the following text:

ed is the standard Unix text editor. This is line number three.

Started with an empty file, the a command appends text (all ed commands are single letters). The command put ed in insert mode, inserting the characters that follow and is terminated by a single dot on a line. The two lines that are entered before the dot end up in the file buffer. The 2i command also 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 to operate on that line.

In the line %l, the lowercase L stands for the list command. The command is prefixed by a range, in this case % which is a shortcut for 1,$. A range is two line numbers separated by a comma ($ means the last line). In return, ed lists 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.

Once the empty line is inserted in line 2, the line which reads "This is line number two." is now actually the third line. This error is corrected with 3s/two/three/, a substitution command. The 3 will apply it to the correct line, following the command is the text to be replaced, and then the replacement. Listing all lines with ,l (a lone comma is also a synonym for %) the line is shown now to be correct.

w text writes the buffer to the file "text" making ed respond with 65, the number of characters written to the file. q will end an ed session.

Read more about this topic:  Ed (text Editor)

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)