Category

Linux Command


Usage

red [-GVhs] [-p string] [file]


Manual

ed is a line-oriented text editor. It is used to create, display, mod-
ify 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 edi-
tor buffer. A typical command might look like:

,s/old/new/g

which replaces all occurrences 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, fol-
lowed 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.



Share your experience or ask a question