ED/COMMANDS 83/08/15
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.,@%, @[, @*)
@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> 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.
RELATED TOPICS
More information is available. Type:
- HELP ED
for information on using the Shell command ED.
- HELP PATTERNS
for details about regular expressions.