Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)

ed(1) OSS Shell and Utilities Reference Manual
NAME
ed - Edits a le line by line
SYNOPSIS
ed [-p string][-s][le]
The ed command invokes a line-editing program that works on one le at a time by copying it into
a temporary edit buffer and making changes to that copy.
FLAGS
-p string Sets the ed prompt to string. The default value for string is null (no prompt).
-s Suppresses byte counts that the editor displays with the e, E, r, and w subcommands,
suppresses diagnostic messages for the e, E, and q subcommands, and suppresses the !
(exclamation point) prompt after a !system_command. The same things are suppressed
when you call ed with a lename.
Note that if you quit without writing the le, you do not get an error message. (Gen-
erally, before ending the program, the q subcommand checks to determine whether the
buffer was written to a le since the last time it was changed. If not, q displays the ?
message.)
DESCRIPTION
The ed command does not alter the le itself until you use the write subcommand. You can
specify on the command line the le you want to edit, or you can use ed subcommands to read a
le into the buffer. When ed reads a new le into the buffer, the contents of that le replace the
buffers previous contents, if any.
The ed Modes
The ed program operates in one of two modes, command mode and text mode. In command mode,
ed recognizes and executes subcommands. In text mode, ed adds text to the le buffer, but does
not recognize subcommands. You enter text mode by using the a, c,ori subcommand. To leave
text mode, enter . (dot) alone at the beginning of a line.
Subcommand Syntax
An ed subcommand consists of zero, one, or two addresses, followed by a single-character sub-
command, possibly followed by arguments to that subcommand. These addresses specify one or
more lines in the buffer. Because every subcommand has default addresses, you frequently do not
need to specify addresses.
Pattern Matching
The ed command supports a limited form of special pattern-matching characters that you can use
as regular expressions (REs) to construct pattern strings. You can use these patterns in addresses
to specify lines and in some subcommands to specify portions of a line.
For information about regular expressions (REs), see the reference page for the grep command.
Addressing
There are three types of ed addresses: line number addresses, addresses relative to the current
line, and pattern addresses.
The current line is the point of reference in the buffer and is represented by a . (dot). When you
start the ed program, the current line is the last line in the buffer. As you edit a le, the current
line changes to the last line affected by a subcommand. The current line is the default address for
several ed commands. (See SUBCOMMANDS to nd out how each subcommand affects the
current line.)
Subcommands for determining and changing the current line are described in the section SUB-
COMMANDS. The following are guidelines for constructing addresses:
342 Hewlett-Packard Company 527188-007