Open System Services Shell and Utilities Reference Manual (G06.27+, H06.04+)
ed(1) OSS Shell and Utilities Reference Manual
NAME
ed - Edits a file line by line
SYNOPSIS
ed [-p string][-s][file]
The ed command invokes a line-editing program that works on one file 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 filename.
Note that if you quit without writing the file, 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 file since the last time it was changed. If not, q displays the ?
message.)
DESCRIPTION
The ed command does not alter the file itself until you use the write subcommand. You can
specify on the command line the file you want to edit, or you can use ed subcommands to read a
file into the buffer. When ed reads a new file into the buffer, the contents of that file replace the
buffer’s 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 file 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 file, 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 find 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:
3−42 Hewlett-Packard Company 527188-004