COHERENT manpages
This page displays the COHERENT manpage for ed [Interactive line editor].
List of available manpages
Index
ed -- Command
Interactive line editor
ed [-] [+cmopsv] [file]
ed is the COHERENT system's interactive line editor.
ed is a line-oriented interactive text editor. With it, you can locate and
replace text patterns, move or copy blocks of text, and print parts of the
text. ed can read text from input files and can write all or part of the
edited text to other files.
ed reads commands from the standard input, usually one command per line.
Normally, ed does not prompt for commands. If the optional file argument
is given, ed edits the given file, as if the file were read with the e
command described below.
ed manipulates a copy of the text in memory rather than with the file
itself. No changes to a file occur until the user writes edited text with
the w command. Large files can be divided with split or edited with the
stream editor sed.
ed remembers some information to simplify its commands. The current line
is typically the line most recently edited or printed. When ed reads in a
file, the last line read becomes the current line. The current file name
is the last file name specified in an e or f command. The current search
pattern is the last pattern specified in a search specification.
ed identifies text lines by integer line numbers, beginning with one for
the first line. Several special forms identify a line or a range of lines,
as follows:
n A decimal number n specifies the nth line of the text.
. A period `.' specifies the current line.
$ A dollar sign `$' specifies the last line of the text.
+,- Simple arithmetic may be performed on line numbers.
/pattern/
Search forward from the current line for the next occurrence of the
pattern. If ed finds no occurrence before the end of the text, the
search wraps to the beginning of the text. Patterns, also called
regular expressions, are described in detail below.
?pattern?
Search backwards from the current line to the previous occurrence of
the pattern. If ed finds no occurrence before the beginning of the
text, the search wraps to the end of the text.
amp;'x
Lines marked with the kx command described below are identified by 'x.
The x may be any lower-case letter.
n,m Line specifiers separated by a comma `,' specify the range of lines
between the two given lines, inclusive.
n;m Line specifiers separated by a semicolon `;' specify the range of
lines between the two given lines, inclusive. Normally, ed updates
the current line after it executes each command. If a semicolon `;'
rather than a comma separates two line specifiers, ed updates the
current line before reading the second.
* An asterisk `*' specifies all lines; it is equivalent to 1,$.
Commands
ed commands consist of a single letter, which may be preceded by one or two
specifiers that give the line or lines to which the command is to be
applied. The following command summary uses the notations [n] and [n[,m]]
to refer to an optional line specifier and an optional range, respectively.
These default to the current line when omitted, except where otherwise
noted. A semicolon `;' may be used instead of a comma `,' to separate two
line specifiers.
. Print the current line. Also, a line containing only a period `.'
marks the end of appended, changed, or inserted text.
[n] Print given line. If no line number is given (i.e., the command line
consists only of a newline character), print the line that follows
the current line.
[n]= Print the specified line number (default: last line number).
[n]&
Print a screen of 23 lines; equivalent to n,n+22p.
! line
Pass the given line to the shell sh for execution. ed prompts with an
exclamation point `!' when execution is completed.
? Print a brief description of the most recent error.
[n]a Append new text after line n. Terminate new text with line that
contains only a period `.'.
[n[,m]]c
Change specified lines to new text. Terminate new text with a line
that contains only a period `.'.
[n[,m]]d[p]
Delete specified lines. If p follows, print new current line.
e [file]
Edit the specified file (default: current file name). An error occurs
if there are unsaved changes. Reissuing the command after the error
message forces ed to edit the file.
E [file]
Edit the specified file (default: current file name). No error occurs
if there are unsaved changes.
f [file]
Change the current file name to file and print it. If file is
omitted, print the current file name.
[n[,m]]g/[pattern]/commands
Globally execute commands for each line in the specified range
(default: all lines) that contains the pattern (default: current
search pattern). The commands may extend over several lines, with all
but the last terminated by `\'.
[n]i Insert text before line n. Terminate new text with a line that
contains only a period `.'.
[n[,m]]j[p]
Join specified lines into one line. If m is not specified, use range
n,n+1. If no range is specified, join the current line with the next
line. With optional p, print resulting line.
[n]kx
Mark given line with lower-case letter x.
[n[,m]]l
List selected lines, interpreting non-graphic characters.
[n[,m]]m[d]
Move selected lines to follow line d (default: current line).
o options
Change the given options. The options may consist of an optional sign
`+' or `-', followed by one or more of the letters `cmopsv'. Options
are explained below.
[n[,m]][p]
Print selected lines. The p is optional.
q Quit editing and exit. An error occurs if there are unsaved changes.
Reissuing the command after the error message forces ed to exit.
Q Quit editing and exit. Throw away all changes that you have not yet
saved to disk.
[n]r [file]
Read file into current text after given line (default: last line).
[n[,m]]s[k]/[pattern1]/pattern2/[g][p]
Search for pattern1 (default, remembered search pattern) and
substitute pattern2 for kth occurrence (default, first) on each line
of the given range. If g follows, substitute every occurrence on each
line. If p follows, print the resulting current line.
[n[,m]]t[d]
Transfer (copy) selected lines to follow line d (default, current
line).
[n]u[p]
Undo effect of last substitute command. If optional p specified,
print undone line. The specified line must be the last substituted
line.
[n[,m]]v/[pattern]/commands
Globally execute commands for each line in the specified range
(default: all lines) not containing the pattern (default: current
search pattern). The commands may extend over several lines, with all
but the last terminated by `\'. The v command is like the g command,
except the sense of the search is reversed.
[n[,m]]w [file]
Write selected lines (default, all lines) to file (default, current
file name). The previous contents of file, if any, are lost.
[n[,m]]W [file]
Write specified lines (default, all lines) to the end of file
(default, current file name). Like w, but appends to file instead of
truncating it.
Patterns
Substitution commands and search specifications may include patterns, also
called regular expressions. A non-special character in a pattern matches
itself. Special characters include the following.
^ Match beginning of line, unless it appears immediately after `[' (see
below).
$ Match end of line.
* Matches zero or more repetitions of preceding character.
. Matches any character except newline.
[chars]
Matches any one of the enclosed chars. Ranges of letters or digits may
be indicated using `-'.
[^chars]
Matches any character except one of the enclosed chars. Ranges of
letters or digits may be indicated using `-'.
\c Disregard special meaning of character c.
\(pattern\)
Delimit substring pattern for use with \d, described below.
The replacement part pattern2 of the substitute command may also use the
following:
&
Insert characters matched by pattern1.
\d Insert substring delimited by dth occurrence of delimiters `\(' and
`\)', where d is a digit.
Options
The user may specify ed options on the command line, in the environment, or
with the o command. The available options are as follows:
c Print character counts on e, r, and w commands.
m Allow multiple commands per line.
o Print line counts instead of character counts on e, r, and w commands.
p Prompt with an `*' for each command.
s Match lower-case letters in a pattern to both upper-case and lower-
case text characters.
v Print verbose versions of error messages.
The c option is normally set, and all others are normally reset. Options
may be set on the command line with a leading `+' sign. The `-' command
line option resets the c option.
Options may be set in the environment with an assignment, such as
export ED=+cv
Options may be set with the `+' prefix or reset with the `-' prefix.
See Also
commands,
elvis,
ex,
me,
sed,
vi
Introduction to the ed Line Editor
Diagnostics
ed usually prints only the diagnostic `?' on any error. When the verbose
option v is specified, the `?' is followed by a brief description of the
nature of the error.






