ED/COMMANDS Aegis ED/COMMANDS
NAME
ed/commands
DESCRIPTION
ed accepts commands interactively (from the keyboard) and in a batch-like
manner (from script files). To use a script file, substitute the script
file name for standard input:
ed [options] [pathname] <script
Command Format
Commands to ed have a consistent format: zero, one, or two line addresses
followed by a single character command, with optional parameters
following the command. The general format is:
[line,][line]command parameters
The [line] specifies a line number or address in the current edit buffer.
There is usually a useful default for each command (normally the current
line) so that you don't need to specify an address explicitly.
Line addresses are formed from the following components:
17 an integer number
. the current line
$ the last line in the buffer
.+n n lines past the current line
.-n n lines before the current line
/pattern/ a forward context search
\pattern\ a backward context search
Line numbers can be separated by commas or semicolons; a semicolon sets
the current line to the previous address before the next address is
interpreted. This feature can be used to determine the starting line for
forward and backward context searches (// and \\).
Regular Expressions
ed supports regular expression notation for specifying patterns in line
addresses and in the s, g, and x commands. A regular expression
represents one or more strings of characters for which to search. For a
description of regular expressions, refer to help patterns. The notation
is summarized below for your convenience. These search and substitute
operations are identical in function to their Display Manager
counterparts, although the syntax of the DM's s command differs slightly.
Summary of Regular Expression Notation
c Literal character
? Any character (except newline)
% Beginning of line
$ End of line
[...] Character class (any one of these characters)
[~...] Negated character class (all characters except those in brackets)
[c1-c2] Any single character in the range c1 to c2
@c Escaped character (e.g.,@@%, @@[, @@*)
@f Form feed
@n Newline
@t Tab character
* Closure (zero or more occurrences of previous pattern)
{...} Tagged pattern
ED COMMANDS IN DETAIL
The following is a list of ed commands. Default line addresses are in
parentheses. Commands may be typed in either upper or lower case.
(.)a
[text]
. The append command reads the text and appends it after the
addressed line. The current line is left on the last line
input, if any. If no lines are input, the current line remains
on the addressed line. Signify the end of the text by typing a
line with a period as its first and only character.
(.)b[+/./-][screensize]
The browse command is a shorthand command to print out a
screenful of data. It has three basic forms, any of which may
be followed by a screensize. A simple b (or b+) prints the
current line and the screenful after it. b- prints the screen
of text preceding (and including) the addressed line. b.
prints a screenful of text, centered on the addressed line.
Except for the b. command, these commands leave the current
line at the last line printed. The default screensize is 23
lines. If you specify a screensize, it becomes the default
screensize for the rest of the editing session or until
changed.
(.,.)c
[text]
. The change command deletes the addressed lines, then accepts
input text which replaces these lines. The current line is
left at the last line input, if there were any, otherwise at
the first line not deleted. Signify the end of the text by
typing a line with a period as its first and only character.
(.,.)d@ The delete command deletes the addressed lines from the buffer.
The line originally after the last line deleted becomes the
current line; however, if the lines deleted were at the end of
the file, the new last line becomes the current line.
e [filename]
The edit command deletes the entire contents of the buffer and
then reads in the named file. When it executes this command,
ed sets the current line to the last line of the buffer and
displays the number of lines read. Also, it remembers the
supplied filename for possible use as a default filename in
subsequent r or w commands.
f [filename]
If you specify a filename, the currently remembered filename is
changed to that name. Otherwise, ed prints the currently
remembered filename.
(1,$)g/regular expression/command
The global command executes the other specified command for
every line that matches the regular expression. To execute
multiple commands on the lines matched, place each on a
separate line and terminate each command except the last with
an at sign (@). For example,
g/foo/s/bar/zot/@ | For all lines containing the string "foo",
s/wazoo/munch/ | replace "bar" with "zot" and "wazoo" with
| "munch".
(.)i
<text>
. The insert command inserts <text> @i[before] the addressed
line. The current line becomes the last line input, or, if
there are no new lines, the addressed line. This command
differs from the a command only in the placement of text.
Signify the end of the text by typing a line with a period as
its first and only character.
(.,.)k<address>
The kopy command copies the addressed lines to the position
after the line specified by <address>. The last of the copied
lines becomes the current line.
(.,.)m<address>
The move command deletes the addressed lines from their
original location, and places them after the line specified by
<address>. The last of the moved lines becomes the current
line.
(.,.)p The print command prints the addressed lines. The last line
printed becomes the current line. The p command can be used as
a modifier following any other command, except the a, c, i, or
q commands. When used in this way, it prints the last line
affected by the command.
q The quit command causes ed to exit. If you have not written
the file since changing it, ed reminds you once to do so.
(.)r [filename]
The read command reads the named file into the buffer after the
addressed line. If you do not specify a filename, ed uses the
remembered filename (see e and f commands). The remembered
filename is not changed. The address 0 (zero) causes ed to
read the file in at the beginning of the buffer. If the read
is successful, the number of lines read is displayed. The last
line read becomes the current line.
(.,.)s/regular expression/replacement/
(.,.)s/regular expression/replacement/g
The substitute command searches each addressed line for an
occurrence of the regular expression. On each line that
contains a match, ed replaces the first occurrence of the
expression with the replacement string. If the global
replacement indicator g follows the command, all occurrences of
the regular expression are replaced. The delimiting character
for the regular expression and replacement need not be a slash
(/); you can use any character except a space or newline. If
the substitution fails on all addressed lines, ed prints a
question mark (?). The last line substituted becomes the
current line. If no regular expression is specified (for
example, s//pat/), ed uses the previous regular expression.
An ampersand (&) in the replacement is replaced by the string that
matched the regular expression. To suppress this special meaning of &,
precede it with an at sign (@@). Note that except for &, all characters
in the replacement string are inserted literally.
To split or merge lines, use the symbol @n to stand for the NEWLINE
character at the end of a line.
(1,$)w [filename]
The write command writes the addressed lines into the file. If
the specified file does not exist, it is created. This command
does not change the remembered filename. If no filename is
given, the remembered filename is used (see the e and f
commands). The current line is left unchanged. If the command
is successful, ed displays the number of lines written.
(1,$)x/regular expression/command
The except command is the same as the global command except
that commands are executed for every line that does not contain
a match for the regular expression.
(.)= The equals command displays the line number of the addressed
line. The current line is not changed.
# comment Text following a pound sign (#) in the first column of a line
is treated as a comment and is ignored by the editor. This
command allows ed scripts to contain comments. Only whole-line
comments are permitted (i.e., you can't place comments at the
ends of other legal command lines).
(.+1)<carriage return>
An address alone on a line causes the addressed line to be
displayed. A blank line alone is equivalent to '.+1' and thus
is useful for stepping through text.
SEE ALSO
ed
for information on using the shell command ED.
patterns
for details about regular expressions.