next up previous contents index
Next: Line numbers in detail Up: Quick Ed Tutorial Previous: Creating a file

editing a existing file

To add a line of text to an existing file follow the next example.

/home/larry# ed firstone.txt
a
This is a new line of text.
.
w
q

If you check the file with cat you'll see that a new line was inserted between the original first and second lines. How did ed know where to place the new line of text?

When ed reads in the file it keeps track of the current line. The command tex2html_wrap8476 will add the text after the current line. ed can also place the text before the current line with the key command tex2html_wrap8486 . The effect will be the insertion of the text before the current line.

Now it is easy to see that ed operates on the text, line by line. All commands can be applied to a chosen line.

To add a line of text at the end of a file.

/home/larry# ed firstone.txt
        $a
        The last line of text.
        .
        w
        q

The command modifier tex2html_wrap8488 tells ed to add the line after the last line. To add the line after the first line the modifier would be tex2html_wrap8490 . The power is now available to select the line to either add a line of text after the line number, or insert a line before the line number.

How do we know what is on the current line? The command key tex2html_wrap8330 will display the contents of the current line. If you want to change the current line to line 2 and see the contents of that line then do the following.

/home/larry# ed firstone.txt
        2p
        q



Converted on:
Mon Apr 1 08:59:56 EST 1996