ED(1)

NAME
ed - text editor

SYNOPSIS
ed [-p prompt] [-s] [file]

DESCRIPTION
ed initially reads its input file into a buffer. If no file argument is provided the buffer will be empty. Commands are then entered to display, modify and save the buffer. Line numbers within the buffer are referred to as addresses. Address 1 is the first line in the buffer; address 0 is invalid.

ed keeps track of the current line selected in the buffer. Commands for modifying the buffer can be entered without an explicit address; the current line will be processed. Entering a bare address such as "2" first resets the current line pointer, then prints the line.

Commands are denoted by a single letter. The "p" command prints one or more lines. An address can precede a command, so "2p" first resets the current line pointer then prints the line. This is the same result as for entering the bare address "2"; however, print is explicit.

A command may operate on a range of addresses at once. An address range is entered as two numbers separated by a comma, e.g. "1,10". The numbers are included as the first and last number of the range. So "1,10" spans from line 1 to 10. A range is then used as a command prefix, e.g. "1,2p" will print 2 lines. Addressing a line outside the scope of the buffer results in an error.

The commands "a", "c" and "i" allow text to be entered into the buffer. Text input is terminated by a line containing the single character ".". If an error occurs ed will print "?". The "h" command fetches the saved error message and prints it.

  OPTIONS
The following options are available:

-p STRING
    Use the specified STRING as a command prompt. By default no prompt is displayed.

-s  Suppress byte counts and diagnostics

  EDITOR COMMANDS

a   Append text

c   Change text

d   Delete text

E FILE
    Forced "e" command; suppress warning prompt

e FILE
    Load and edit the named FILE argument

f [FILE]
    Show/set a filename

H   Toggle help mode; this causes descriptive errors to be displayed

h   Display last error

i   Insert text

j   Join a range of lines into a single line. The current address is set to the destination address.

kCH Mark an address with the lowercase letter CH. The mark can then be used as 'CH in place of an address.

l   Print lines with escape sequences for non-printable characters

m   Move a range of lines to a new address. The current address is set to the last line moved.

n   Print from buffer with line number prefix

P   Toggle command prompt mode. A string provided by -p will be used; otherwise, the default is '*'

p   Print from buffer

Q   Forced "q" command; suppress warning prompt

q   Quit program

r FILE
    Read named FILE into buffer

/PATTERN
    Search for PATTERN in the buffer, starting from the current line. If no pattern is given the previous search is repeated.

?PATTERN
    Search backwards for PATTERN in the buffer, starting from the current line. If no pattern is given the previous search is repeated.

g/PATTERN/CMD
    Search globally in buffer for PATTERN and run command CMD on each matching line. CMD is one of the following commands: 'd', 'l', 'n', 'p' and 's'. CMD can be omitted.

v/PATTERN/CMD
    Repeatedly run command CMD for each line in the buffer not matching PATTERN. CMD is one of the following commands: 'd', 'l', 'n', 'p' and 's'. CMD can be omitted.

s///
    Substitute text with a regular expression

t   Copy (transfer) lines to a destination address. The current address is set to the last line copied.

u   Undo the last command, restoring the editor buffer to its previous state. The current address is set to what it was before the previous command. The undo function is its own inverse, so multiple levels of undo are not possible.

W [FILE]
    Write buffer to file in append mode

w [FILE]
    Write buffer to file

wq [FILE]
    Write buffer to file, then quit

=   Display current line number

EXIT STATUS

•   0 - All commands were processed successfully

•   1 - An error occurred

AUTHOR
Written by George M Jones