On Thu, 26 Dec 2002, Richard Levitte - VMS Whacker wrote:
> In message <[EMAIL PROTECTED]> on
>Wed, 25 Dec 2002 21:03:37 -0800 (PST), Tim Rice <[EMAIL PROTECTED]> said:
>
> tim> > I'll try and work on it between getting a server ready to install on monday.
> tim> > I've attached a couple of sed man pages. (in case you figure it out first)
>
> Hmm, they both refer to ed for regular expressions...
>
Those last minute e-mails before crawling off to bed will get you every time.
I've attached the ed man pages.
Perhaps we are going down the wrong path. Instead of wasting our time
trying to figure out each platform's sed, maybe we should be using perl.
Perl should work the same on all platforms.
Unfortunately neither of these work
perl -pi -e 's/ \?\([\.,@]\) */\1/g;' -e 's/ *:/:/g;' -e 's/#.*//'
/tmp/testfile
perl -pi -e 's/ +\([\.,:@]\) +/\1/g;' -e 's/#.*//' /tmp/testfile
for lines like
. type md5_block_asm_host_order , @ function
--
Tim Rice Multitalents (707) 887-1469
[EMAIL PROTECTED]
ed(C) 19 June 1992 ed(C)
Name
ed, red - invoke the text editor
Syntax
ed [ - ] [ -p string ] [ file ]
red [ - ] [ -p string ] [ file ]
Description
ed is the standard text editor. If the file argument is given, ed simu-
lates 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. ed operates on a
copy of the file it is editing; changes made to the copy have no effect
on the 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(C). It will only allow editing of
files in the current directory. It prohibits executing sh(C) commands
via the ! command. red displays an error message on any attempt to bypass
these restrictions.
In general, red does not allow commands like !date or !sh.
Furthermore, red will not allow pathnames in its command line. For exam-
ple, the command:
red /etc/passwd
when the current directory is not /etc causes an error.
Options
The options to ed are:
- Suppresses the printing of character counts by the e, r, and w
commands, of diagnostics from e and q commands, and the ``!''
prompt after a ! shell command.
-p Allows the user to specify a prompt string.
ed supports formatting capability. After including a format specifica-
tion as the first line of file and invoking ed with your terminal in
stty-tabs or sttytab3 mode (see stty(C)), the specified tab stops will
automatically be used when scanning file. For example, if the first line
of a file contained:
<:t5,10,15 s72:>
tab stops would be set at columns 5, 10, and 15, and a maximum line
length of 72 would be imposed.
Note: While inputting text, tab characters are expanded to every eighth
column as the default.
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 may appear on a line. Certain commands
allow the input of text. This text is placed in the appropriate place in
the buffer. While ed is accepting text, it is said to be in input mode.
In this mode, no commands are recognized; all input is merely collected.
Input mode is left by entering a period (.) alone at the beginning of a
line.
ed supports a limited form of regular expression notation; regular
expressions are used in addresses to specify lines and in some commands
(for example, s) to specify portions of a line that are to be substi-
tuted. A regular expression specifies a set of character strings. A
member of this set of strings is said to be matched by the regular
expression. The regular expressions allowed by ed are constructed as
follows:
The following one-character regular expressions match a single character:
1.1 An ordinary character (not one of those discussed in 1.2 below) is a
one-character regular expression that matches itself.
1.2 A backslash (\) followed by any special character is a one-character
regular expression that matches the special character itself. The
special characters are:
a. . * [ and \ (dot, star, left square bracket, and backslash,
respectively), which are otherwise special, except when they
appear within square brackets ([ ]); see 1.4 below).
b. ^ (caret), which is special at the beginning of an entire regu-
lar expression (see 3.1 and 3.2 below), or when it immediately
follows the left of a pair of square brackets (see 1.4 below).
c. $ (dollar sign), which is special at the end of an entire regu-
lar expression (see 3.2 below).
d. The character used to bound (that is, delimit) an entire regu-
lar expression, which is special for that regular expression
(for example, see how slash (/) is used in the g command
below).
1.3 A period (.) is a one-character regular expression that matches any
character except newline.
1.4 A nonempty string of characters enclosed in square brackets is a
one-character regular expression that matches any one character in
that string. If, however, the first character of the string is a
caret (^), the one-character regular expression matches any charac-
ter except newline and the remaining characters in the string. The
star (*) also has this special meaning only if it occurs first in
the string. The dash (-) may be used to indicate a range of con-
secutive ASCII characters; for example, [0-9] is equivalent to
[0123456789]. The dash loses this special meaning if it occurs
first (after an initial caret, if any) or last in the string. The
right square bracket (]) does not terminate such a string when it is
the first character within it (after an initial caret, if any); for
example, [ ]a-f] matches either a right square bracket or one of the
letters ``a'' through ``f'' inclusive. Dot, star, left bracket, and
the backslash lose their special meaning within such a string of
characters.
Ranges of characters (characters separated by ``-'' are treated according
to the current locale's collation sequence (see locale(M)). Therefore,
if the collation sequence in use is A, a, B, b, C, c, then the expression
[a-d] is equivalent to the expression [aBbCcDd].
To specify a collation item within a class, the item must be enclosed
between ``[.'' and ``.]''. Two character to one collation item mappings
must be specified this way. For example, if the current collation rules
specify that the characters ``Ch'' map to one character for collation
purposes (as in Spanish), then this collation item would be specified as
[.Ch.] .
To specify a group of collation items, which are classified as equal
unless all other collation items in the string also match, in which case
a secondary ``weight'' becomes significant, a single member of that group
must be enclosed between ``[='' and ``=]''. For example, if the charac-
ters A and a are in the same group then the class expressions [[=a=]b],
[[=A=]b] and [Aab] are all equivalent.
The ctype classes can also be specified within regular expressions.
These are enclosed between [: and :] . The possible ctype classes are:
[:alpha:] Matches alphabetic characters
[:upper:] Matches upper case characters
[:lower:] Matches lower case characters
[:digit:] Matches digits
[:alnum:] Matches alphanumeric characters
[:space:] Matches white space
[:print:] Matches printable characters
[:punct:] Matches punctuation marks
[:graph:] Matches graphical characters
[:cntrl:] Matches control characters
The following rules may be used to construct regular expressions from
one-character regular expressions:
2.1 A one-character regular expression followed by a star (*) is a regu-
lar expression that matches zero or more occurrences of the one-
character regular expression. If there is any choice, the longest
leftmost string that permits a match is chosen.
2.2 A one-character regular expression followed by \{m\}, \{m,\}, or
\{m,n\} is a regular expression that matches a range of occurrences
of the one-character regular expression. The values of m and n must
be nonnegative integers less than 255; \{m\} matches exactly m oc-
currences; \{m,\} matches at least m occurrences; \{m,n\} matches
any number of occurrences between m and n, inclusive. Whenever a
choice exists, the regular expression matches as many occurrences as
possible.
2.3 The concatenation of regular expressions is a regular expression
that matches the concatenation of the strings matched by each com-
ponent of the regular expression.
2.4 A regular expression enclosed between the character sequences ``\(''
and ``\)'' is a regular expression that matches whatever the una-
dorned regular expression matches. See 2.5 below for a discussion
of why this is useful.
2.5 The expression \n matches the same string of characters as was
matched by an expression enclosed between \( and \) earlier in the
same regular expression. Here n is a digit; the subexpression
specified is that beginning with the n-th occurrence of \( counting
from the left. For example, the expression \(.*\)\1$ matches a line
consisting of two repeated appearances of the same string.
Finally, an entire regular expression may be constrained to match only an
initial segment or final segment of a line (or both):
3.1 A caret at the beginning of an entire regular expression constrains
that regular expression to match an initial segment of a line.
3.2 A dollar sign ($) at the end of an entire regular expression con-
strains that regular expression to match a final segment of a line.
The construction ^entire regular expression$ constrains the entire
regular expression to match the entire line.
The null regular expression (for example, //) is equivalent to the last
regular expression encountered.
To understand addressing in ed, it is necessary to know that there is a
current line at all times. Generally speaking, the current line is the
last line affected by a command; the exact effect on the current line is
discussed under the description of each command. Addresses are con-
structed as follows:
1. The character ``.'' addresses the current line.
2. The character ``$'' addresses the last line of the buffer.
3. A decimal number n addresses the n-th line of the buffer.
4. 'x addresses the line marked with the mark name character x, which
must be a lowercase letter. Lines are marked with the k command
described below.
5. A regular expression enclosed by slashes (/) addresses the first
line found by searching forward from the line following the current
line toward the end of the buffer and stopping at the first line
containing a string matching the regular expression. If necessary,
the search wraps around to the beginning of the buffer and contin-
ues up to and including the current line, so that the entire buffer
is searched.
6. A regular expression enclosed in question marks (?) addresses the
first line found by searching backward from the line preceding the
current line toward the beginning of the buffer and stopping at the
first line containing a string matching the regular expression. If
necessary, the search wraps around to the end of the buffer and
continues up to and including the current line. See also the last
paragraph before ``Files'' below.
7. An address followed by a plus sign (+) or a minus sign (-) followed
by a decimal number specifies that address plus or minus the indi-
cated number of lines. The plus sign may be omitted.
8. If an address begins with ``+'' or ``-'', the addition or subtrac-
tion is taken with respect to the current line; for example, -5 is
understood to mean .-5.
9. If an address ends with ``+'' or ``-'', then 1 is added to or sub-
tracted from the address, respectively. As a consequence of this
rule and of rule 8 immediately above, the address ``-'' refers to
the line preceding the current line. (To maintain compatibility
with earlier versions of the editor, the character ``^'' in
addresses is entirely equivalent to ``-''.) Moreover, trailing
``+'' and ``-'' characters have a cumulative effect, so ``--''
refers to the current line less 2.
10. For convenience, a comma (,) stands for the address pair 1, $,
while a semicolon (;) stands for the pair . , $.
Commands may require zero, one, or two addresses. Commands that require
no addresses regard the presence of an address as an error. Commands
that accept one or two addresses assume default addresses when an insuf-
ficient number of addresses is given; if more addresses are given than
such a command requires, the last address(es) are used.
Typically, addresses are separated from each other by a comma. They may
also be separated by a semicolon. In the latter case, the current line
(.) is set to the first address, and only then is the second address cal-
culated. This feature can be used to determine the starting line for
forward and backward searches (see rules 5 and 6 above). The second
address of any two-address sequence must correspond to a line that fol-
lows, in the buffer, the line corresponding to the first address.
In the following list of ed commands, the default addresses are shown in
parentheses. The parentheses are not part of the address.
It is generally illegal for more than one command to appear on a line.
However, any command (except e, f, r, or w) may be suffixed by p or by l,
in which case the current line is either printed or listed, respectively,
as discussed below under the p and l commands.
( . )a
<text>
. The append command reads the given text and appends it after
the addressed line; dot is left at the address of the last
inserted line, or, if there were no inserted lines, at the
addressed line. Address 0 is legal for this command: it causes
the appended text to be placed at the beginning of the buffer.
( . )c
<text>
. The change command deletes the addressed lines, then accepts
input text that replaces these lines; dot is left at the
address of the last line input, or, if there were none, at the
first line that was not deleted.
( . , . )d
The Delete command deletes the addressed lines from the buffer.
The line after the last line deleted becomes the current line;
if the lines deleted were originally at the end of the buffer,
the new last line becomes the current line.
e file The edit command causes the entire contents of the buffer to be
deleted, and then the named file to be read in; dot is set to
the last line of the buffer. If no filename is given, the
currently remembered filename, if any, is used (see the f com-
mand). The number of characters read is typed. file is remem-
bered for possible use as a default filename in subsequent e,
r, and w commands. If file begins with an exclamation (!), the
rest of the line is taken to be a shell command. The output of
this command is read for the e and r commands. For the w com-
mand, the file is used as the standard input for the specified
command. Such a shell command is not remembered as the current
filename.
E file The Edit command is like e, except the editor does not check to
see if any changes have been made to the buffer since the last
w command.
f file If file is given, the filename command changes the currently
remembered filename to file; otherwise, it prints the currently
remembered filename.
( 1 , $ )g/regular-expression/command list
In the global command, the first step is to mark every line
that matches the given regular expression. Then, for every
such line, the given command list is executed with ``.'' ini-
tially set to that line. A single command or the first of a
list of commands appears on the same line as the global com-
mand. All lines of a multiline list except the last line must
be ended with a ``\''; a, i, and c commands and associated
input are permitted; the ``.'' terminating input mode may be
omitted if it would be the last line of the command list. An
empty command list is equivalent to the p command. The g, G,
v, and V commands are not permitted in the command list. See
also ``Notes'' and the last paragraph before ``Files'' below.
( 1 , $ )G/regular-expression/
In the interactive Global command, the first step is to mark
every line that matches the given regular expression. Then,
for every such line, that line is printed, dot (.) is changed
to that line, and any one command (other than one of the a, c,
i, g, G, v, and V commands) may be input and is executed.
After the execution of that command, the next marked line is
printed, and so on. A newline acts as a null command. An
ampersand (&) causes the re-execution of the most recent com-
mand executed within the current invocation of G. Note that the
commands input as part of the execution of the G command may
address and affect any lines in the buffer. The G command can
be terminated by entering an INTERRUPT (pressing the <Del>
key).
h The help command gives a short error message that explains the
reason for the most recent ? diagnostic.
H The Help command causes ed to enter a mode in which error mes-
sages are printed for all subsequent ? diagnostics. It will
also explain the previous diagnostic if there was one. The H
command alternately turns this mode on and off. It is initially
off.
( . )i
<text>
. The insert command inserts the given text before the addressed
line; dot is left at the address of the last inserted line, or
if there were no inserted lines, at the addressed line. This
command differs from the a command only in the placement of the
input text. Address 0 is not legal for this command.
( . , .+1 )j
The join command joins contiguous lines by removing the
appropriate newline characters. If only one address is given,
this command does nothing.
( . )kx The mark command marks the addressed line with name x, which
must be a lowercase letter. The address 'x then addresses this
line. Dot is unchanged.
( . , . )l
The list command prints the addressed lines in an unambiguous
way: a few nonprinting characters (for example, tab, back-
space) are represented by mnemonic overstrikes, all other
nonprinting characters are printed in octal, and long lines are
folded. An l command may be appended to any command other than
e, f, r, or w.
( . , . )ma
The move command repositions the addressed line(s) after the
line addressed by a. Address 0 is legal for a and causes the
addressed line(s) to be moved to the beginning of the file. It
is an error if address a falls within the range of moved lines.
Dot is left at the last line moved.
( . , . )n
The number command prints the addressed lines, preceding each
line by its line number and a tab character. Dot is left at
the last line printed. The n command may be appended to any
command other than e, f, r, or w.
( . , . )p
The print command prints the addressed lines. Dot is left at
the last line printed. The p command may be appended to any
command other than e, f, r, or w; for example, dp deletes the
current line and prints the new current line.
P The editor will prompt with a ``*'' for all subsequent com-
mands. The P command alternately turns this mode on and off.
It is initially off.
q The quit command causes ed to exit. No automatic write of a
file is done.
Q The editor exits without checking if changes have been made in
the buffer since the last w command.
( $ )r file
The read command reads in the given file after the addressed
line. If no filename is given, the currently remembered
filename, if any, is used (see e and f commands). The
currently remembered filename is not changed unless file is the
very first filename mentioned since ed was invoked. Address 0
is legal for r and causes the file to be read at the beginning
of the buffer. If the read is successful, the number of char-
acters read is typed. Dot is set to the address of the last
line read in. If file begins with ``!'', the rest of the line
is taken to be a shell command whose output is to be read.
Such a shell command is not remembered as the current filename.
( . , . )s/regular-expression/replacement or
( . , . )s/regular-expression/replacement/g or
( . , . )s/regular-expression/replacement/n n=1-512
The substitute command searches each addressed line for an oc-
currence of the specified regular expression. In each line in
which a match is found, all nonoverlapped matched strings are
replaced by replacement if the global replacement indicator g
appears after the command. If the global indicator does not
appear, only the first occurrence of the matched string is
replaced. It is an error for the substitution to fail on all
addressed lines. Any character other than space or newline may
be used instead of ``/'' to delimit regular-expression and
replacement. Dot is left at the address of the last line on
which a substitution occurred.
The n character represents any number between one and 512.
This number indicates the instance of the pattern to be
replaced on each addressed line.
An ampersand (&) appearing in replacement is replaced by the
string matching the regular-expression on the current line.
The special meaning of the ampersand in this context may be
suppressed by preceding it with a backslash. The characters
\n, where n is a digit, are replaced by the text matched by the
n-th regular subexpression of the specified regular expression
enclosed between ``\('' and ``\)''. When nested parenthesized
subexpressions are present, n is determined by counting occur-
rences of ``\('' starting from the left. When the character
``%'' is the only character in replacement, the replacement
used in the most recent substitute command is used as the
replacement in the current substitute command. The ``%'' loses
its special meaning when it is in a replacement string of more
than one character or when it is preceded by a ``\''.
A line may be split by substituting a newline character into
it. The newline in the replacement must be escaped by preced-
ing it with a ``\''. Such a substitution cannot be done as
part of a g or v command list.
( . , . )ta
This command acts just like the m command, except that a copy
of the addressed lines is placed after address a (which may be
0). Dot is left at the address of the last line of the copy.
u The undo command nullifies the effect of the most recent com-
mand that modified anything in the buffer, namely the most
recent a, c, d, g, i, j, m, r, s, t, v, G, or V command.
( 1 , $ )v/regular-expression/command list
This command is the same as the global command g except that
the command list is executed with dot initially set to every
line that does not match the regular expression.
( 1 , $ )V/regular-expression/
This command is the same as the interactive global command G
except that the lines that are marked during the first step are
those that do not match the regular expression.
( 1 , $ )w file
The write command writes the addressed lines into the named
file. If the file does not exist, it is created with mode 666
(readable and writeable by everyone), unless the umask setting
(see sh(C)) dictates otherwise. The currently remembered
filename is not changed unless file is the very first filename
mentioned since ed was invoked. If no filename is given, the
currently remembered filename, if any, is used (see e and f
commands), and dot remains. If the command is successful, the
number of characters written is displayed. If file begins with
an exclamation (!), the rest of the line is taken to be a shell
command to which the addressed lines are supplied as the stan-
dard input. Such a shell command is not remembered as the
current filename.
( $ )= The line number of the addressed line is typed. Dot is
unchanged by this command.
!shell command
The remainder of the line after the ``!'' is sent to the UNIX
shell (sh(C)) to be interpreted as a command. Within the text
of that command, the unescaped character ``%'' is replaced with
the remembered filename. If a ``!'' appears as the first char-
acter of the shell command, it is replaced with the text of the
previous shell command. Thus, ``!!'' will repeat the last
shell command. If any expansion is performed, the expanded
line is echoed. Dot is unchanged.
( .+1 ) An address alone on a line causes the addressed line to be
printed. A RETURN alone on a line is equivalent to .+1p. This
is useful for stepping forward through the editing buffer a
line at a time.
If an interrupt signal (ASCII DEL or BREAK) is sent, ed prints a question
mark (?) and returns to its command level.
ed has size limitations: 512 characters per line, 256 characters per glo-
bal command list, 64 characters per filename, and 128K characters in the
buffer. The limit on the number of lines depends on the amount of user
memory.
When reading a file, ed discards ASCII NUL characters and all characters
after the last newline. Files (for example, a.out) that contain charac-
ters not in the ASCII set (bit 8 on) cannot be edited by ed.
If the closing delimiter of a regular expression or of a replacement
string (for example, ``/'') would be the last character before a newline,
that delimiter may be omitted, in which case the addressed line is
printed. Thus, the following pairs of commands are equivalent:
s/s1/s2 s/s1/s2/p
g/s1 g/s1/p
?s1 ?s1?
Files
/tmp/e# Temporary; # is the process number
ed.hup Work is saved here if the terminal is hung up
See also
coltbl(M), grep(C), locale(M), regexp(S), sed(C), sh(C), stty(C)
Diagnostics
? Command errors
? file An inaccessible file
Use the help and Help commands for detailed explanations.
If changes have been made in the buffer since the last w command that
wrote the entire buffer, ed warns the user if an attempt is made to de-
stroy ed's buffer via the e or q commands by printing ``?'' and allowing
you to continue editing. A second e or q command at this point will take
effect. The dash (-) command-line option inhibits this feature.
Notes
An exclamation (!) command cannot be subject to a g or a v command.
The ! command and the ! escape from the e, r, and w commands cannot be
used if the the editor is invoked from a restricted shell (see sh(C)).
The sequence \n in a regular expression does not match any character.
The l command mishandles DEL.
Because 0 is an illegal address for the w command, it is not possible to
create an empty file with ed.
If the editor input is coming from a command file; that is,
ed file < ed-cmd-file
the editor will exit at the first failure of a command in the command
file.
Standards conformance
ed is conformant with:
AT&T SVID Issue 2;
and X/Open Portability Guide, Issue 3, 1989.
ed(1) ed(1)
NAME
ed, red - text editor
SYNOPSIS
ed [-s] [-p string] [-x] [-C] [file]
red [-s] [-p string] [-x] [-C] [file]
DESCRIPTION
ed is the standard text editor. If the file argument is
given, ed simulates 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. Both ed and red process supplementary
code set characters in file, and recognize supplementary code
set characters in the prompt string given to the -p option
(see below) according to the locale specified in the LC_CTYPE
environment variable [see LANG on environ(5)]. In regular
expressions, pattern searches are performed on characters, not
bytes, as described below.
-s Suppresses the printing of byte counts by e, E, r, and w
commands, of diagnostics from e and q commands, and of
the ! prompt after a !shell command.
-p Allows the user to specify a prompt string. The string
may contain supplementary code set characters.
-x Encryption option; when used, ed simulates an X command
and prompts the user for a key. This key is used to
encrypt and decrypt text using the algorithm of
crypt(1). The X command makes an educated guess to
determine whether text read in is encrypted or not. The
temporary buffer file is encrypted also, using a
transformed version of the key typed in for the -x
option. See crypt(1). Also, see the NOTICES section at
the end of this manual page.
-C Encryption option; the same as the -x option, except
that ed simulates a C command. The C command is like
the X command, except that all text read in is assumed
to have been encrypted.
ed operates on a copy of the file it is editing; changes made
to the copy have no effect on the 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.
Copyright 1995 Novell, Inc. Page 1
ed(1) ed(1)
red is a restricted version of ed. It will only allow editing
of files in the current directory. It prohibits executing
shell commands via !shell command. Attempts to bypass these
restrictions result in an error message (restricted shell).
Both ed and red support the fspec formatting capability.
After including a format specification as the first line of
file and invoking ed with your terminal in stty -tabs or
stty tab3 mode the specified tab stops will automatically be
used when scanning file. For example, if the first line of a
file contained:
<:t5,10,15 s72:>
tab stops would be set at columns 5, 10, and 15, and a maximum
line length of 72 would be imposed. NOTE: when you are
entering text into the file, this format is not in effect;
instead, because of being in stty -tabs or stty tab3 mode,
tabs are expanded to every eighth column.
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 may appear on a line. Certain
commands allow the input of text. This text is placed in the
appropriate place in the buffer. While ed is accepting text,
it is said to be in input mode. In this mode, no commands are
recognized; all input is merely collected. Leave input mode
by typing a period (.) at the beginning of a line, followed
immediately by pressing RETURN.
ed supports a limited form of regular expression notation;
regular expressions are used in addresses to specify lines and
in some commands (for example, s) to specify portions of a
line that are to be substituted. A regular expression
specifies a set of character strings. A member of this set of
strings is said to be matched by the regular expression. [See
grep(1) for complete regular expression information.]
To understand addressing in ed it is necessary to know that at
any time there is a current line. Generally speaking, the
current line is the last line affected by a command; the exact
effect on the current line is discussed under the description
Copyright 1995 Novell, Inc. Page 2
ed(1) ed(1)
of each command. Addresses are constructed as follows:
1. The character . addresses the current line.
2. The character $ addresses the last line of the buffer.
3. A decimal number n addresses the n-th line of the
buffer.
4. 'x addresses the line marked with the mark name
character x, which must be a lower-case letter (a-z).
Lines are marked with the k command described below.
5. A regular expression enclosed by slashes (/) addresses
the first line found by searching forward from the line
following the current line toward the end of the buffer
and stopping at the first line containing a string
matching the regular expression. If necessary, the
search wraps around to the beginning of the buffer and
continues up to and including the current line, so that
the entire buffer is searched. See also the last
paragraph of the DESCRIPTION section below.
6. A regular expression enclosed in question marks (?)
addresses the first line found by searching backward
from the line preceding the current line toward the
beginning of the buffer and stopping at the first line
containing a string matching the regular expression.
If necessary, the search wraps around to the end of the
buffer and continues up to and including the current
line. See also the last paragraph of the DESCRIPTION
section below.
7. An address followed by a plus sign (+) or a minus sign
(-) followed by a decimal number specifies that address
plus (respectively minus) the indicated number of
lines. A shorthand for .+5 is .5.
8. If an address begins with + or -, the addition or
subtraction is taken with respect to the current line;
for example, -5 is understood to mean .-5.
9. If an address ends with + or -, then 1 is added to or
subtracted from the address, respectively. As a
consequence of this rule and of Rule 8, immediately
above, the address - refers to the line preceding the
Copyright 1995 Novell, Inc. Page 3
ed(1) ed(1)
current line. (To maintain compatibility with earlier
versions of the editor, the character ^ in addresses is
entirely equivalent to -.) Moreover, trailing +and -
characters have a cumulative effect, so -- refers to
the current line less 2.
10. For convenience, a comma (,) stands for the address
pair 1,$, while a semicolon (;) stands for the pair
.,$.
Commands may require zero, one, or two addresses. Commands
that require no addresses regard the presence of an address as
an error. Commands that accept one or two addresses assume
default addresses when an insufficient number of addresses is
given; if more addresses are given than such a command
requires, the last one(s) are used.
Typically, addresses are separated from each other by a comma
(,). They may also be separated by a semicolon (;). In the
latter case, the first address is calculated, the current line
(.) is set to that value, and then the second address is
calculated. This feature can be used to determine the
starting line for forward and backward searches (see Rules 5
and 6, above). The second address of any two-address sequence
must correspond to a line in the buffer that follows the line
corresponding to the first address.
In the following list of ed commands, the parentheses shown
prior to the command are not part of the address; rather they
show the default address(es) for the command.
The file arguments of the e, E, f, r, w, and W commands are
subject to pattern matching as in sh(1), They should be
separated from the command letter by one or more spaces or
tabs.
It is generally illegal for more than one command to appear on
a line. However, any command (except e, f, r, or w) may be
suffixed by l, n, or p in which case the current line is
either listed, numbered or printed, respectively, as discussed
below under the l, n, and p commands.
(.)a
<text>
. The append command accepts zero or more lines of text
and appends it after the addressed line in the buffer.
The current line (.) is left at the last inserted line,
Copyright 1995 Novell, Inc. Page 4
ed(1) ed(1)
or, if there were none, at the addressed line. Address
0 is legal for this command: it causes the ``appended''
text to be placed at the beginning of the buffer. The
maximum number of bytes that may be entered from a
terminal is {LINE_MAX} per line (including the new-line
character). {LINE_MAX} is defined in limits.h.
(.)c
<text>
. The change command deletes the addressed lines from the
buffer, then accepts zero or more lines of text that
replaces these lines in the buffer. The current line
(.) is left at the last line input, or, if there were
none, at the first line that was not deleted.
C Same as the X command, described later, except that ed
assumes all text read in for the e and r commands is
encrypted unless a null key is typed in.
(.,.)d
The delete command deletes the addressed lines from the
buffer. The line after the last line deleted becomes
the current line; if the lines deleted were originally
at the end of the buffer, the new last line becomes the
current line.
e file
The edit command deletes the entire contents of the
buffer and then reads the contents of file into the
buffer. The current line (.) is set to the last line of
the buffer. If file is not given, the currently
remembered file name, if any, is used (see the f
command). The number of characters read in is printed;
file is remembered for possible use as a default file
name in subsequent e, r, and w commands. If file is
replaced by !, the rest of the line is taken to be a
shell [sh(1)] command whose output is to be read in.
Such a shell command is not remembered as the current
file name. See also DIAGNOSTICS below.
E file
The Edit command is like e, except that the editor does
not check to see if any changes have been made to the
buffer since the last w command.
Copyright 1995 Novell, Inc. Page 5
ed(1) ed(1)
f file
If file is given, the file-name command changes the
currently remembered file name to file; otherwise, it
prints the currently remembered file name.
(1,$)g/regular expression/command list
In the global command, the first step is to mark every
line that matches the given regular expression. Then,
for every such line, the given command list is executed
with the current line (.) initially set to that line. A
single command or the first of a list of commands
appears on the same line as the global command. All
lines of a multi-line list except the last line must be
ended with a \; a, i, and c commands and associated
input are permitted. The . terminating input mode may
be omitted if it would be the last line of the command
list. An empty command list is equivalent to the p
command. The g, G, v, and V commands are not permitted
in the command list. See the NOTICES section and the
last paragraph of the DESCRIPTION section below.
(1,$)G/regular expression/
In the interactive Global command, the first step is to
mark every line that matches the given regular
expression. Then, for every such line, that line is
printed, the current line (.) is changed to that line,
and any one command (other than one of the a, c, i, g,
G, v, and V commands) may be input and is executed.
After the execution of that command, the next marked
line is printed, and so on; a new-line acts as a null
command; an & causes the re-execution of the most recent
command executed within the current invocation of G.
Note that the commands input as part of the execution of
the G command may address and affect any lines in the
buffer. The G command can be terminated by an interrupt
signal (ASCII DEL or BREAK).
h The help command gives a short error message that
explains the reason for the most recent ? diagnostic.
H The Help command causes ed to enter a mode in which
error messages are printed for all subsequent ?
diagnostics. It will also explain the previous ? if
there was one. The H command alternately turns this
mode on and off; it is initially off.
Copyright 1995 Novell, Inc. Page 6
ed(1) ed(1)
(.)i
<text>
. The insert command accepts zero or more lines of text
and inserts it before the addressed line in the buffer.
The current line (.) is left at the last inserted line,
or, if there were none, at the addressed line. This
command differs from the a command only in the placement
of the input text. Address 0 is not legal for this
command. The maximum number of characters that may be
entered from a terminal is {LINE_MAX} per line
(including the new-line character). {LINE_MAX} is
defined in limits.h.
(.,.+1)j
The join command joins contiguous lines by removing the
appropriate new-line characters. If exactly one address
is given, this command does nothing.
(.)kx The mark command marks the addressed line with name x,
which must be a lower-case letter (a-z). The address 'x
then addresses this line; the current line (.) is
unchanged.
(.,.)l
The list command prints the addressed lines in an
unambiguous way: a few non-printing characters (for
example, tab, backspace) are represented by visually
mnemonic overstrikes. All other non-printing characters
are printed in octal, long lines are folded and the end
of each line is marked with a $. An l command may be
appended to any command other than e, f, r, or w.
(.,.)ma
The move command repositions the addressed line(s) after
the line addressed by a. Address 0 is legal for a and
causes the addressed line(s) to be moved to the
beginning of the file. It is an error if address a
falls within the range of moved lines; the current line
(.) is left at the last line moved.
(.,.)n
The number command prints the addressed lines, preceding
each line by its line number and a tab character; the
current line (.) is left at the last line printed. The
n command may be appended to any command other than e,
f, r, or w.
Copyright 1995 Novell, Inc. Page 7
ed(1) ed(1)
(.,.)p
The print command prints the addressed lines; the
current line (.) is left at the last line printed. The
p command may be appended to any command other than e,
f, r, or w. For example, dp deletes the current line
and prints the new current line.
P The editor will prompt with a * for all subsequent
commands. The P command alternately turns this mode on
and off; it is initially off.
q The quit command causes ed to exit. No automatic write
of a file is done; however, see DIAGNOSTICS below.
Q The editor exits without checking if changes have been
made in the buffer since the last w command.
($)r file
The read command reads the contents of file into the
buffer. If file is not given, the currently remembered
file name, if any, is used (see the e and f commands).
The currently remembered file name is not changed unless
file is the very first file name mentioned since ed was
invoked. Address 0 is legal for r and causes the file
to be read in at the beginning of the buffer. If the
read is successful, the number of characters read in is
printed; the current line (.) is set to the last line
read in. If file is replaced by !, the rest of the line
is taken to be a shell [see sh(1)] command whose output
is to be read in.
For example, $r !ls appends current directory to the end
of the file being edited. Such a shell command is not
remembered as the current file name.
(.,.)s/regular expression/replacement/ or
(.,.)s/regular expression/replacement/g or
(.,.)s/regular expression/replacement/n n = 1-512
The substitute command searches each addressed line for
an occurrence of the specified regular expression. In
each line in which a match is found, all (non-
overlapped) matched strings are replaced by the
replacement if the global replacement indicator g
appears after the command. If the global indicator does
not appear, only the first occurrence of the matched
string is replaced. If a number n, appears after the
Copyright 1995 Novell, Inc. Page 8
ed(1) ed(1)
command, only the n-th occurrence of the matched string
on each addressed line is replaced. It is an error if
the substitution fails on all addressed lines. Any
character other than space or new-line may be used
instead of / to delimit the regular expression and the
replacement; the current line (.) is left at the last
line on which a substitution occurred. See also the
last paragraph of the DESCRIPTION section below.
An ampersand (&) appearing in the replacement is
replaced by the string matching the regular expression
on the current line. The special meaning of & in this
context may be suppressed by preceding it by \. As a
more general feature, the characters \n, where n is a
digit, are replaced by the text matched by the n-th
regular subexpression of the specified regular
expression enclosed between \( and \). When nested
parenthesized subexpressions are present, n is
determined by counting occurrences of \( starting from
the left. When the character % is the only character in
the replacement, the replacement used in the most recent
substitute command is used as the replacement in the
current substitute command. The % loses its special
meaning when it is in a replacement string of more than
one character or is preceded by a \.
A line may be split by substituting a new-line character
into it. The new-line in the replacement must be
escaped by preceding it by \. Such substitution cannot
be done as part of a g or v command list.
(.,.)ta
This command acts just like the m command, except that a
copy of the addressed lines is placed after address a
(which may be 0); the current line (.) is left at the
last line copied.
u The undo command nullifies the effect of the most recent
command that modified anything in the buffer, namely the
most recent a, c, d, g, i, j, m, r, s, t, v, G, or V
command.
(1,$)v/regular expression/command list
This command is the same as the global command g, except
that the lines marked during the first step are those
that do not match the regular expression.
Copyright 1995 Novell, Inc. Page 9
ed(1) ed(1)
(1,$)V/regular expression/
This command is the same as the interactive global
command G, except that the lines that are marked during
the first step are those that do not match the regular
expression.
(1,$)w file
The write command writes the addressed lines into file.
If file does not exist, it is created with mode 666
(readable and writable by everyone), unless your file
creation mask dictates otherwise; see the description of
the umask special command on sh(1). The currently
remembered file name is not changed unless file is the
very first file name mentioned since ed was invoked. If
no file name is given, the currently remembered file
name, if any, is used (see the e and f commands); the
current line (.) is unchanged. If the command is
successful, the number of characters written is printed.
If file is replaced by !, the rest of the line is taken
to be a shell command whose standard input is the
addressed lines. Such a shell command is not remembered
as the current file name.
(1,$)W file
This command is the same as the write command above,
except that it appends the addressed lines to the end of
file if it exists. If file does not exist, it is
created as described above for the w command.
X A key is prompted for, and it is used in subsequent e,
r, and w commands to decrypt and encrypt text using the
crypt(1) algorithm. An educated guess is made to
determine whether text read in for the e and r commands
is encrypted. A null key turns off encryption.
Subsequent e, r, and w commands will use this key to
encrypt or decrypt the text [see crypt(1)]. An
explicitly empty key turns off encryption. Also, see
the -x option of ed.
($)= The line number of the addressed line is typed; the
current line (.) is unchanged by this command.
!shell command
The remainder of the line after the ! is sent to the
UNIX system shell to be interpreted as a command. See
sh(1). Within the text of that command, the unescaped
Copyright 1995 Novell, Inc. Page 10
ed(1) ed(1)
character % is replaced with the remembered file name;
if a ! appears as the first character of the shell
command, it is replaced with the text of the previous
shell command. Thus, !! will repeat the last shell
command. If any expansion is performed, the expanded
line is echoed; the current line (.) is unchanged.
(.+1)<new-line>
An address alone on a line causes the addressed line to
be printed. A new-line alone is equivalent to .+1p; it
is useful for stepping forward through the buffer.
If an interrupt signal (ASCII DEL or BREAK) is sent, ed prints
a ? and returns to its command level.
Some size limitations: {LINE_MAX} bytes in a line, 256 bytes
in a global command list, and {PATH_MAX} bytes in the pathname
of a file (counting slashes). {LINE_MAX} and {PATH_MAX} are
defined in limits.h. The limit on the number of lines depends
on the amount of user memory: each line takes 1 word.
When reading a file, ed discards ASCII NUL characters.
If a file is not terminated by a new-line character, ed adds
one and puts out a message explaining what it did.
If the closing delimiter of a regular expression or of a
replacement string (for example, /) would be the last
character before a new-line, that delimiter may be omitted, in
which case the addressed line is printed. The following pairs
of commands are equivalent:
s/s1/s2 s/s1/s2/p
g/s1 g/s1/p
?s1 ?s1?
Errors
? for command errors.
?file for an inaccessible file.
(use the help and Help commands for detailed
explanations).
If changes have been made in the buffer since the last w
command that wrote the entire buffer, ed warns the user if an
attempt is made to destroy ed's buffer via the e or q
commands. It prints ? and allows one to continue editing. A
Copyright 1995 Novell, Inc. Page 11
ed(1) ed(1)
second e or q command at this point will take effect. The -s
command-line option inhibits this feature.
Files
$TMPDIR
if this environmental variable is not null, its value
is used in place of /var/tmp as the directory name for
the temporary work file.
/var/tmp
if /var/tmp exists, it is used as the directory name
for the temporary work file.
/tmp if the environmental variable TMPDIR does not exist or
is null, and if /var/tmp does not exist, then /tmp is
used as the directory name for the temporary work file.
ed.hup work is saved here if the terminal is hung up.
/usr/lib/locale/locale/LC_MESSAGES/uxcore.abi
language-specific message file [see LANG on
environ(5)].
REFERENCES
edit(1), ex(1), fspec(4), grep(1), regexp(5), sed(1), sh(1),
stty(1), umask(1), vi(1)
NOTICES
The - option, although it continues to be supported, has been
replaced in the documentation by the -s option that follows
the Command Syntax Standard [see intro].
The encryption options and commands are provided with the
Encryption Utilities package, which is available only in the
United States.
A ! command cannot be subject to a g or a v command.
The ! command and the ! escape from the e, r, and w commands
cannot be used if the editor is invoked from a restricted
shell [see sh(1)].
The sequence \n in a regular expression does not match a new-
line character.
Copyright 1995 Novell, Inc. Page 12
ed(1) ed(1)
If the editor input is coming from a command file (for
example, ed file < ed_cmd_file), the editor exits at the first
failure.
The following environment variables affect the execution of
ed: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, LC_TIME, TZ [see LANG
on environ(5)].
Copyright 1995 Novell, Inc. Page 13