Editing files

Moving around in ed

Instead of showing you a screen of text, ed works with line addresses; the line or lines in a file to which it applies a command.

When you start ed, it displays the number of bytes in the file. You begin at line 1; to move to a different line, enter its line number and press <Enter>. ed echoes the contents of the line. Press <Enter> to step through the file a line at a time. You can also enter relative line numbers; for example, -2 to go back two lines, +5 to go forward five.

The special address ``.'' refers to the current line, ``$'' to the last line of the file.

To discover the current line number, enter the command n. This also outputs the contents of the line.

To see the contents of your file, use the l (short for list) command. Entering l on its own prints the current line. To list several lines, prefix l with the start and end line numbers separated by a comma (,), For example, to list lines 10 to 20 of a file, enter:


This command sets your current line number to the last line displayed (20).

For convenience, a comma (,) represents the address pair ``1,$'' (that is, the entire file), while a semicolon (;) stands for ``.,$'' (current line to end of file). For example, ,l lists the entire file.

You can use relative addresses; for example, $-5 means the fifth line before the last line of the file, while .+2 means the second line after the current line.

Next topic: Editing text in ed
Previous topic: Saving files and quitting ed

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003