DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
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:

10,20l

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.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004