[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    ED(1) manual page Table of Contents

Name

ed, red - text editor

Synopsis

ed [-] [-Gs] [-p string] [file]

red [-] [-Gs] [-p string] [file]

Description

ed is a line-oriented text editor. It is used to create, display, modify and otherwise manipulate text files. red is a restricted ed: it can only edit files in the current directory and cannot execute shell commands.

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 ‘w’ command are lost.

Editing is done in two distinct modes: command and input. When first invoked, ed is 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:

,s/old/new/g

which replaces all occurences of the string old with new.

When an input command, such as ‘a’ (append), ‘i’ (insert) or ‘c’ (change), is given, ed enters 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 ed commands operate on whole lines or ranges of lines; e.g., the ‘d’ command deletes lines; the ‘m’ command 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 ‘s’ command is applied to whole lines at a time.

In general, ed commands consist of zero or more line addresses, followed by a single character command and possibly additional parameters; i.e., commands have the structure:

[address [,address]]command[parameters]

The address(es) indicate the line or range of lines to be affected by the command. If fewer addresses are given than the command accepts, then default addresses are supplied.

Options

-G
Forces backwards compatibility. Affects the commands ‘G’, ‘V’, ‘f’, ‘l’, ‘m’, ‘t’, and ‘!!’.
-s
Suppresses diagnostics. This should be used if ed’s standard input is from a script.

-p string
Specifies a command prompt. This may be toggled on and off with the ‘P’ command.

file
Specifies the name of a file to read. If file is prefixed with a bang (!), 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.

Line Addressing

An address represents the number of a line in the buffer. ed maintains 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 (i.e., +, - 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 semicolon. The value of the first address in a range cannot exceed the value of the 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 semicolon-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.