ed.1 (2010 09)
e
ed(1) ed(1)
NAME
ed, red - line-oriented text editor
SYNOPSIS
ed [-p string ][-s
-][-x][file]
red [-p string ][-s
-][-x][file]
DESCRIPTION
The
ed command executes a line-oriented text editor. It is most commonly used in scripts and nonin-
teractive editing applications because, even though it can be used interactively, other editors such as
vi
and ex are typically easier to use in an interactive environment.
If file is specified,
ed performs an e command (see below) on the named file; that is to say, the file is read
into
ed’s buffer so that it can be edited.
Options
The following options are recognized:
-p string Use string as the prompt string when in command mode. By default, there is no
prompt string.
-s- Suppress printing of byte counts by e, E, r, and
w commands, and suppress the !
prompt after a ! command . The - option is obsolescent and will be removed in a
future release.
-x Perform an X command first to handle an encrypted file.
File Handling
ed operates on a copy of the file it is editing; changes made to the copy have no effect on the original file
until a w (write) command is given. The copy of the text being edited resides in a temporary file called
the buffer . There is only one buffer.
red is a restricted version of ed that only allows editing of files in the current directory and prohibits
executing shell commands via !shell-command. Attempts to bypass these restrictions result in the error
message
restricted shell.
Both
ed and red support the fspec (4) formatting capability. After including a format specification as the
first line of file and invoking ed with the controlling terminal in stty -tabs
or stty tab3 mode (see
stty (1)), the specified tab stops are automatically used when scanning file. For example, if the first line of
a file contained
<:t5,10,15 s72:>
the tab stops would be set at columns 5, 10, and 15, and a maximum line length of 72 would be imposed.
Note: When you input text,
ed expands tab characters as they are typed to every eighth column as a
default.
Editor Commands Structure
Commands to
ed have a simple and regular structure: zero, one, or two addresses followed by a single-
character command, possibly followed by parameters to that command. These addresses specify one or
more lines in the buffer. Every command that requires addresses has default addresses, so that the
addresses can very often be omitted.
In general, only one command is allowed on a line. Append, change, and insert commands accept text
input which is then placed in the buffer as appropriate. While
ed is accepting text following an append,
change, or insert command, it is said to be in input mode. While in input mode, no editor commands are
recognized; all input is merely collected. To terminate input mode, type a period (.) alone at the begin-
ning of a line.
Regular Expressions
ed supports the Basic Regular Expression (RE) syntax (see regexp (5)), with the following additions:
• The null RE (for example,
//) is equivalent to the last RE encountered.
• If the closing delimiter of an RE or of a replacement string (for example,
/) would be the last
character before a newline, that delimiter can be omitted, in which case the addressed line is
printed. The following pairs of commands are equivalent:
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1