|ED(1)||General Commands Manual||ED(1)|
edis a line-oriented text editor. It is used to create, display, modify, and otherwise manipulate text files. If invoked with a file argument, then a copy of file is read into the editor's buffer. Changes are made to this copy and not directly to file itself. Upon quitting
ed, any changes not explicitly saved with a
wcommand are lost. Editing is done in two distinct modes: command and input. When first invoked,
edis in command mode. In this mode, commands are read from the standard input and executed to manipulate the contents of the editor buffer. A typical command might look like:
c(change) is given,
edenters input mode. This is the primary means of adding text to a file. In this mode, no commands are available; instead, the standard input is written directly to the editor buffer. Lines consist of text up to and including a newline character. Input mode is terminated by entering a single period (‘
.’) on a line. All
edcommands operate on whole lines or ranges of lines; e.g., the
dcommand deletes lines; the
mcommand moves lines, and so on. It is possible to modify only a portion of a line by means of replacement, as in the example above. However, even here, the
scommand is applied to whole lines at a time. In general,
edcommands consist of zero or more line addresses, followed by a single character command and possibly additional parameters; i.e., commands have the structure:
edcommands and line addresses support basic regular expressions (BREs). See re_format(7) for more information on regular expressions. The options are as follows:
edstandard input is from a script.
!’), then it is interpreted as a shell command. In this case, what is read is the standard output of file executed via sh(1). To read a file whose name begins with a bang, prefix the name with a backslash (‘
\’). The default filename is set to file only if it is not prefixed with a bang.
edmaintains a current address which is typically supplied to commands as the default address when none is specified. When a file is first read, the current address is set to the last line of the file. In general, the current address is set to the last line affected by a command. A line address is constructed from one of the bases in the list below, optionally followed by a numeric offset. The offset may include any combination of digits, operators (e.g., ‘
-’, and ‘
^’), and whitespace. Addresses are read from left to right, and their values are computed relative to the current address. One exception to the rule that addresses represent line numbers is the address 0 (zero). This means “before the first line”, and is legal wherever it makes sense. An address range is two addresses separated either by a comma or semi-colon. The value of the first address in a range cannot exceed the value of the second. If only one address is given in a range, then the second address is set to the given address. If an n-tuple of addresses is given where n > 2, then the corresponding range is determined by the last two addresses in the n-tuple. If only one address is expected, then the last address is used. Each address in a comma-delimited range is interpreted relative to the current address. In a semi-colon-delimited range, the first address is used to set the current address, and the second address is interpreted relative to the first. The following address symbols are recognized:
k(mark) command, where lc is a lower case letter.
edcommands are single characters, though some require additional parameters. If a command's parameters extend over several lines, then each line except for the last must be terminated with a backslash (‘
\’). In general, at most one command is allowed per line. However, most commands accept a print suffix, which is any of
n(enumerate), to print the last line affected by the command.
edrecognizes the following commands. The commands are shown together with the default address or address range supplied if none is specified (in parentheses), and other possible arguments on the right.
!command below). The default filename is un