ed, redline-oriented text editor |
Command |
ed
[-bsTx
]
[-p
prompt] [file]
red
[-bsTx
]
[-p
prompt] [file]
ed
is a line-oriented text editor that lets you manipulate
text files interactively. ed
reads the text of a file into
memory and stores it in an area called a buffer. Various commands let you
edit the text in the buffer. Finally, you can write the contents of the buffer
back out to the file, overwriting the old contents of the file.
red
is a restricted version of ed
. It is
intended to protect the novice user by disallowing the !
command and the ability to access files found anywhere but the current directory.
-b
lets you edit larger files by restricting the amount of memory
dedicated to paging. This frequently makes ed
run
slower. This option has no benefit on UNIX or POSIX-compliant
systems.
-p
promptdisplays the given prompt string prompting you to input a
command. By default, ed
does not prompt for command
input. See the description of the P
command for more
on command prompting.
-s
puts ed
into a quiet mode, in which the
E
, e
, r
and
w
commands do not display file size counts; the
e
and qe
commands do not check
buffer modification and ed
does not display
!
after calling the shell to execute a sub-command. This mode
is particularly useful when you invoke ed
from within
a shell script.
-T
causes file to have only newline instead of the usual carriage return/newline combination (Windows systems only).
-x
performs an X
command to handle encrypted files
properly. See the description of the X
command for
more details.
ed
reads the specified file into the buffer by
simulating an e
file command.
ed
with zero, one, or two
addresses. These addresses let you reference single lines or ranges of lines in
the buffer. You do not need to specify addresses for certain commands that use
default addresses. Consult the command's description for the default addresses.
You can construct each address out of the following components:
.
e
command sets it to the last line of the new file
being edited.$
/
regexp/
regexp
). The search begins
at the line immediately following the current line. It proceeds
forward through the buffer; if ed
reaches the
end of the buffer without finding a match, it wraps around to the first
line of the buffer and continues the search. If ed
does not find a match, the search ends when it reaches the original
current line. If it finds a match, the address
/
regexp/
refers to the
first matching line. If you omit regexp, the last used regular
expression becomes the object of the search. You can omit the trailing
/
. Within regexp, \/
represents a literal
slash and not the regexp delimiter.?
regexp?
ed
wraps around
and continues searching backward from the last line in the buffer. If you
omit regexp, the last used regular expression becomes the object of
the search. You can omit the trailing ?
. Within regexp,
\?
represents a literal question mark and not the
regexp delimiter.'
lk
command.+
and
-
operators, with the usual interpretation (so .+1
is
the current line plus one). Missing left operands (+1
) default to
.
(dot); missing right operands (.+
or +
)
default to 1
. Missing right operands also have a cumulative effect;
so an address of --
refers to the current line number less 2.
You can specify address ranges in the following ways:
,
a21,$
.;
a2ed
resets
the current line number after calculating a1, so that the second
address, a2, is relative to a1. Omitting a1 and
a2 (that is, specifying only the semicolon), is equivalent to
.;$
.
If you specify only a1 and the command requires both a1 and a2, the command operates as though you specified a range of
a1;. command
>
>
is
equivalent to .,.+22
except that it never attempts to address
any line beyond $
.<
>
, except that it displays the
previous page of text. On a 25 line screen,
<
is equivalent to .-22,.
except that
it never addresses any line before line 1.ed
command has the form:
All commands end with a new-line--you must press ENTER. Most commands allow only one command on a line, although most commands can be modified by appending the[address]command
l
, n
, and p
commands.
Commands generally take a maximum of zero, one, or two addresses, depending upon
the particular command. In the following descriptions, we show commands with
their default addresses (that is the addresses used when you don't specify any
addresses) in a form that shows the maximum number of legal addresses for the
command.
The E
, e
, r
,
W
and w
commands allow you to specify a
file argument. For these commands, file can be either a path name
or a shell escape of the form:
If you use the!command-line
!
form, ed
calls the shell
identified by the SHELL
environment variable to
execute command-line. For the E
, e
and r
commands, ed
reads the standard
output of this command line in the same way that it read the contents of a file.
For the W
and w
commands, the command
line treats the addressed lines as standard input.
The commands G
, g
, k
,
m
, s
, t
,
V
, and v
take parameters.
ed
accepts the following commands:
a
appends text after the specified line. Valid addresses range
from 0
(text is placed at the beginning of the buffer, before
the first line) to $
(text is placed after the last line of
the buffer). ed
reads lines of text from the terminal
until a line consisting solely of an unescaped .
(dot)
is entered. ed
sets the current line number to the
last line appended.
c
changes the addressed range of lines by deleting the lines and then
reading new text in the manner of the a
or
i
commands.
d
deletes the addressed range of lines. The line after the last line
deleted becomes the new current line. If you delete the last line of the
buffer, ed
sets the current line number to the new
last line. If no lines remain in the buffer, it sets the current line
number to 0.
E
[file]replaces the contents of the current buffer with the contents of
file, like the e
command. Unlike
e
, however, the E
command gives no
warning if you have changed the current buffer without writing the
contents.
e
[file]replaces the contents of the current buffer with the contents of
file. If you did not specify file, ed
uses the remembered file name, if any. In all cases, the
e
command sets the remembered file name to the
file that it has just read into the buffer. ed
displays a count of the bytes in the file unless it is in quiet
mode. If you have changed the current buffer since the last time its
contents were written out, ed
displays a warning
message and does not execute the command. If you enter the
e
command a second time, ed
executes the command.
f
[file]changes the remembered file name to file; file can
be a complete path name. ed
displays the new
remembered file name. If you do not specify file,
ed
displays the current remembered file
name.
G/
regexp/
is similar to the g
command except that it is
interactive. When ed
finds a line that matches
regexp, it displays the line and waits for you to type in the
command to be executed. You cannot use the a ,
c ,
i ,
G ,
g ,
V ,
and v
commands. If you enter &
, the G
command re-executes the last command you typed in. If you press ENTER,
G
does not execute any command for that line.
g/
regexp/
command listperforms command on all lines that contain strings matching the
regular expression regexp. This command works in two passes. In the
first pass, ed
searches the given range of lines and
marks all those that contain strings matching the regular expression
regexp, while the second pass actually performs command on
those lines. You cannot use !
, G
,
g
, V
, or v
as
command. command consists of one or more
ed
commands, the first of which must appear on the
same line as the g
commands. All lines except the last
of a multi-line command list must end with a backslash (\
).
If command list is empty, ed
assumes it to be
the p
command. If no lines match regexp,
ed
does not change the current line number; otherwise,
the current line number is the one set by the last command in
command. You can use any character other than space or newline
instead of the slash (/
) to delimit regexp.
H
tells ed
to display descriptive messages when
errors occur, or if ed
is already displaying
descriptive messages, returns ed
to terse error
messages. Normally, ed
indicates error messages by
displaying a ?
. When you turn on descriptive error messages
with this command, ed
also displays the descriptive
message for the most recent ?
message (see the description of
the h
command).
h
provides a brief explanation of the last error that occurred. This does not change the current line number.
i
works like the a
command except that
ed
inserts the text before the addressed line.
Valid addresses range from line 1
to $
(the last
line). ed
sets the current line number to the last
inserted line.
j
joins a range of lines into one line. To be precise, the
j
command removes all newline characters from the
addressed range of lines, except for the last one. ed
sets the current line number to the resulting combined line.
k
lmarks the addressed line with the mark name l, which is a single
lowercase letter of the alphabet. This lets you refer to a marked line
with the construct '
l. This is called an
absolute address because it always refers to the same line,
regardless of changes to the buffer.
l
displays the addressed range of lines, representing non-printable
characters visibly. The end of a line is represented by the $
character, and the characters \\
, \a
,
\b
, \f
, \r
, \t
and
\v
are printed as escape sequences. Each non-printable
character is either represented as one of the above escape sequences or as
a three-digit octal number. Lines which are too long to fit on one line
are folded. You can append the l
command to most other
commands to check on the effect of those commands. ed
sets the current line number to the last line so displayed.
m
amoves the addressed lines to the point immediately following the line
given by the address a. The address a must not be in the
range of addressed lines. If address a is 0
,
ed
moves the lines to the beginning of the buffer. The
last line moved becomes the new current line.
n
displays the addressed lines in a way similar to the
p
command, but ed
puts the line
number and a tab character at the beginning of each line. The last line
displayed becomes the new current line. You can append
n
to any command other than E
,
e
, f
, Q
,
q
, r
, w
, or
!
to check on the effect of that command.
P
turns on command prompting. If you specified the -p
prompt option on the ed
command line,
ed
displays the prompt string whenever it is
ready for you to type in another command. If you did not specify
-p
, ed
uses the *
character as a prompt. If command prompting is currently turned on,
issuing the P
command turns it off.
p
displays the addressed lines. The last line displayed becomes the new
current line. You can append p
to any command other
than E
, e
, f
,
Q
, q
, r
,
w
, or !
to check on the effect of
that command.
Q
quits unconditionally, without checking for buffer modifications.
q
exits ed
. If you have made changes to the buffer
since the last save, ed
issues a warning. Entering the
q
command again lets you quit, regardless of unsaved
changes.
r
[file]reads the contents of file into the buffer after the addressed
line. If the address is 0
, ed
places the
text before the first line in the buffer. If you do not specify
file, ed
uses the remembered file name;
if no remembered file name exists, file becomes the new
remembered name. The r
command displays the
number of bytes read from file unless you specified the
-s
option. The last line read from the file becomes
the new current line. If file is replaced by !
, the
rest of the line is considered a shell command line, the output of which
is to be read.
s/
regexp/
new/
[flags]searches the specified range of lines for strings matching the regular
expression regexp. Normally the s
command
replaces the first such matching string in each line with the string
new. The s
command sets the current line number
to the last line on which a substitution occurred. If
ed
makes no such replacements, ed
considers it an error. flags can be zero or more of the following:
g
l
l
commandn
n
commandp
p
commandYou can use any printable character other than the space or newline
instead of /
to separate parts of the command provided that
you use the same character to delimit all parts of the command. If you
omit the trailing delimiter, ed
behaves as though you
had used the flag p
.
You can include a newline in the new string by putting a
\
immediately in front of the newline. This is a good way to
split a line into two lines. If new consists only of the
%
character, s
uses the new string
from the previous s
command. If &
appears anywhere in new, ed
replaces it with
the text matching the regexp. If you want new to contain a
literal ampersand or percent sign, put a backslash (\
) in
front of the &
or %
character.
t
acopies the addressed lines to the point after the line given by
the address a. The address a must not fall in the range of
addressed lines. If address a is 0
,
ed
copies the lines to the beginning of the buffer.
This sets the current line to the last line copied.
u
rolls back the effect of the last command that changed the buffer. For
the purposes of u
, commands that change the buffer are:
a
, c
, d
,
g
, G
, i
,
j
, m
, r
,
s
, t
, v
,
V
and (of course) u
. This means
that typing u
repeatedly flips the most recent change
back and forth. ed
treats all changes made by a global
command (G
, g
,
V
, or v
) as a single change. As a
result, such changes can be easily undone. This command sets the current
line number to the value it had immediately before you issued the command
being undone.
V/
regexp/
is similar to the G
command except that this
command only gives you the chance to edit lines that do not match
the given regular expression.
v/
regexp/
commandsis similar to the g
(global) command except that
ed
only applies the given commands to lines
that do not match the given regular expression.
W
[file]is similar to the w
command except that this
command appends data to the given file if the file already
exists.
w
[file]writes the addressed lines of the buffer to the named file. This
does not change the current line number. If you do not provide file,
ed
uses the remembered file name; if there is
no remembered file name, file becomes the remembered
name. If the output file does not exist, ed
creates it.
ed
displays the number of characters written unless
you had specified the -s
option.
X
prompts you to enter an encryption key. All subsequent
e
, r
and w
commands use this key to decrypt/encrypt text read from or written to
files. To turn off encryption, issue an X
command and
press RETURN in response to the prompt for an encryption key.
!
commandruns command as if you typed it to your chosen command
interpreter. If command contains the %
character,
ed
replaces it with the current remembered file
name. If you want a command to contain a literal %
, put a
backslash (\
) in front of the character. As a special case,
typing !!
re-issues the previous command.
=
displays the line number of the addressed line. This does not change the current line number.
,.
+1if you supply zero, one, or two addresses without an explicit command,
ed
displays the addressed lines in the mode of the
last display command: p
, l
, or
n
. This sets the current line number to the last line
displayed.
COLUMNS
contains the terminal width in columns. ed
folds
lines at that point.
HOME
contains the path name of your home directory.
SHELL
contains the full path name of the current shell.
TMPDIR
is the path name of the directory being used for temporary files. If it
is not set, MKS Toolkit uses /tmp
.
/tmp/e*
This is the paging file. It holds a copy of the file being
edited. You can change the directory for temporary files using the
environment variable TMPDIR
(see
envvar
).
ed.hup
ed
writes the current buffer to this file when it
receives a hang-up signal.
0
Successful completion.
1
Failure because of any of the following:
m
and t
commands require
destination addressm
and
t
g
, v
,
G
, or V
x
command has become X
(uppercase)2
Usage error, such as unknown command line option.
The range of lines being moved or copied by m
or
t
cannot include the destination address.
There is a limit on the length of a global instruction
(g
or v
).
You must follow the m
or t
commands with an address indicating where you want to move or copy text.
You omitted this address.
You tried to execute a command that used a remembered file name
(For example, you used w
to write without specifying
an output file name). However, there is no remembered file name at
present. Issue the command again, but specify a file name this
time.
The command line invoked the restricted form of ed
,
but you tried an action that was not allowed in the restricted editor (the
!
command).
You ran out of space on disk or encountered other errors involving the page file stored in the temporary file.
You issued a command to quit editing the current file (for example,
q
or e
to edit a new file);
however, you have changed the file since the last time you saved it.
ed
is suggesting that you save the file before you
exit it; otherwise, your recent changes are lost. To save the file, use
the w
command. If you really do not want to save the
recent changes, use q
to quit or e
to edit a new file.
An unspecified error occurred. Use the h
or
H
command for more information.
ed
comes from a script rather than a
terminal, ed
exits when any error occurs.
<
and >
, the
-b
, -T
and -x
options, and the W
and X
commands are
extensions to the POSIX and XPG standards.
The red
command is also an extension to the POSIX and XPG
standards.