

ed                           Command                           ed




Interactive line editor

eedd [-] [+ccmmooppssvv] [_f_i_l_e]

ed is the COHERENT system's interactive line editor.

ed is a line-oriented  interactive text editor.  With it, you can
locate and  replace text patterns,  move or copy  blocks of text,
and print parts  of the text.  ed can read  text from input files
and can write all or part of the edited text to other files.

ed reads  commands from the  standard input, usually  one command
per line.   Normally, ed  does not  prompt for commands.   If the
optional file  argument is given, ed edits the  given file, as if
the file were read with the e command described below.

ed manipulates a copy of the  text in memory rather than with the
file itself.   No changes to  a file occur until  the user writes
edited text with the w  command.  Large files can be divided with
split or edited with the stream editor sed.

ed remembers some information to simplify its commands.  The cur-
rent line is typically  the line most recently edited or printed.
When ed reads  in a file, the last line  read becomes the current
line.  The  current file name is the last  file name specified in
an e or  f command.  The current search pattern  is the last pat-
tern specified in a search specification.

ed identifies text  lines by integer line numbers, beginning with
one for the first line.  Several special forms identify a line or
a range of lines, as follows:

_n    A decimal number n specifies the nth line of the text.

.    A period `.' specifies the current line.

$    A dollar sign `$' specifies the last line of the text.

+,-  Simple arithmetic may be performed on line numbers.

/_p_a_t_t_e_r_n/
     Search forward from the current line for the next occurrence
     of the pattern.  If ed finds no occurrence before the end of
     the text,  the search  wraps to  the beginning of  the text.
     Patterns, also called  regular expressions, are described in
     detail below.

?_p_a_t_t_e_r_n?
     Search backwards  from the current line  to the previous oc-
     currence of  the pattern.  If ed  finds no occurrence before
     the beginning  of the text,  the search wraps to  the end of
     the text.




COHERENT Lexicon                                           Page 1




ed                           Command                           ed



'_x   Lines  marked with the kx command  described below are iden-
     tified by 'x.  The x may be any lower-case letter.

_n,_m  Line  specifiers separated by a comma  `,' specify the range
     of lines between the two given lines, inclusive.

_n;_m   Line specifiers  separated by a  semicolon `;'  specify the
     range of lines between the two given lines, inclusive.  Nor-
     mally, ed  updates the current  line after it  executes each
     command.  If  a semicolon `;' rather  than a comma separates
     two  line specifiers,  ed  updates the  current line  before
     reading the second.

*    An  asterisk `*'  specifies all  lines; it is  equivalent to
     1,$.

***** Commands *****

ed commands consist of a  single letter, which may be preceded by
one or  two specifiers that give  the line or lines  to which the
command is to be applied.  The following command summary uses the
notations [_n] and [_n[,_m]]  to refer to an optional line specifier
and an  optional range, respectively.  These  default to the cur-
rent line  when omitted, except  where otherwise noted.   A semi-
colon `;' may be used instead of a comma `,' to separate two line
specifiers.

.     Print the  current line.   Also, a  line containing  only a
     period `.'  marks the end of  appended, changed, or inserted
     text.

[_n]  Print  given line.   If no line  number is given  (i.e., the
     command line  consists only of  a  newline character), print
     the line that follows the current line.

[_n]= Print the specified line number (default: last line number).

[_n]& Print a screen of 23 lines; equivalent to _n,_n+2222pp.

! _l_i_n_e
     Pass  the given  line  to the  shell sh  for execution.   ed
     prompts with an exclamation point `!' when execution is com-
     pleted.

?    Print a brief description of the most recent error.

[_n]aa Append new text after  line n.  Terminate new text with line
     that contains only a period `.'.

[_n[,_m]]cc
     Change specified lines to new text.  Terminate new text with
     a line that contains only a period `.'.

[_n[,_m]]dd[pp]
     Delete  specified lines.   If p  follows, print  new current


COHERENT Lexicon                                           Page 2




ed                           Command                           ed



     line.

ee [_f_i_l_e]
     Edit the  specified file  (default: current file  name).  An
     error occurs  if there  are unsaved changes.   Reissuing the
     command after the error message forces ed to edit the file.

EE [_f_i_l_e]
     Edit the  specified file  (default: current file  name).  No
     error occurs if there are unsaved changes.

ff [_f_i_l_e]
     Change the current file name  to file and print it.  If file
     is omitted, print the current file name.

[_n[,_m]]gg/[_p_a_t_t_e_r_n]/_c_o_m_m_a_n_d_s
     Globally  execute commands  for each  line in  the specified
     range  (default:  all   lines)  that  contains  the  pattern
     (default: current search  pattern).  The commands may extend
     over several lines, with all but the last terminated by `\'.

[_n]ii Insert  text before line n.  Terminate new  text with a line
     that contains only a period `.'.

[_n[,_m]]jj[pp]
     Join specified lines into  one line.  If m is not specified,
     use range n, If no range is specified, join the current line
     with the next line.  With optional p, print resulting line.

[_n]kk_x
     Mark given line with lower-case letter x.

[_n[,_m]]ll
     List selected lines, interpreting non-graphic characters.

[_n[,_m]]mm[_d]
     Move  selected  lines to  follow  line  d (default:  current
     line).

oo _o_p_t_i_o_n_s
     Change  the given  options.  The options  may consist  of an
     optional sign  `+' or  `-', followed by  one or more  of the
     letters `ccmmooppssvv'.  Options are explained below.

[_n[,_m]][pp]
     Print selected lines.  The p is optional.

qq    Quit editing and exit.  An error occurs if there are unsaved
     changes.  Reissuing the command after the error message for-
     ces ed to exit.

QQ    Quit editing and exit.  No error occurs if there are unsaved
     changes.




COHERENT Lexicon                                           Page 3




ed                           Command                           ed



[_n]rr [_f_i_l_e]
     Read file into  current text after given line (default: last
     line).

[_n[,_m]]ss[_k]/[_p_a_t_t_e_r_n_1]/_p_a_t_t_e_r_n_2/[gg][pp]
     Search for pattern1 (default, remembered search pattern) and
     substitute pattern2  for kth occurrence  (default, first) on
     each  line of  the given  range.   If g  follows, substitute
     every  occurrence on  each line.   If  p follows,  print the
     resulting current line.

[_n[,_m]]tt[_d]
     Transfer (copy)  selected lines  to follow line  d (default,
     current line).

[_n]uu[pp]
     Undo  effect  of last  substitute  command.   If optional  p
     specified, print  undone line.   The specified line  must be
     the last substituted line.

[_n[,_m]]vv/[_p_a_t_t_e_r_n]/_c_o_m_m_a_n_d_s
     Globally  execute commands  for each  line in  the specified
     range  (default:  all  lines)  not  containing  the  pattern
     (default: current search  pattern).  The commands may extend
     over several lines, with all but the last terminated by `\'.
     The v command is like the g command, except the sense of the
     search is reversed.

[_n[,_m]]ww [_f_i_l_e]
     Write selected lines  (default, all lines) to file (default,
     current file name).   The previous contents of file, if any,
     are lost.

[_n[,_m]]WW [_f_i_l_e]
     Write  specified lines  (default, all lines)  to the  end of
     file (default,  current file name).  Like  w, but appends to
     file instead of truncating it.

***** Patterns *****

Substitution commands and  search specifications may include pat-
terns, also called  regular expressions.  A non-special character
in  a pattern  matches  itself.  Special  characters include  the
following.

^    Match beginning of line, unless it appears immediately after
     `[' (see below).

$    Match end of line.

*    Matches zero or more repetitions of preceding character.

.    Matches any character except newline.




COHERENT Lexicon                                           Page 4




ed                           Command                           ed



[_c_h_a_r_s]
     Matches any one of the enclosed chars.  Ranges of letters or
     digits may be indicated using `-'.

[^_c_h_a_r_s]
     Matches  any character  except  one of  the enclosed  chars.
     Ranges of letters or digits may be indicated using `-'.

\_c   Disregard special meaning of character c.

\(_p_a_t_t_e_r_n\)
     Delimit substring pattern for use with \_d, described below.

The replacement part  pattern2 of the substitute command may also
use the following:

&    Insert characters matched by pattern1.

\_d   Insert  substring delimited by dth  occurrence of delimiters
     `\(' and `\)', where d is a digit.

***** Options *****

The user may  specify ed options on the command  line, in the en-
vironment, or  with the o command.  The  available options are as
follows:

cc    Print character counts on e, r, and w commands.

mm    Allow multiple commands per line.

oo    Print line counts instead of character counts on e, r, and w
     commands.

pp    Prompt with an `*' for each command.

ss    Match lower-case letters in a pattern to both upper-case and
     lower-case text characters.

vv    Print verbose versions of error messages.

The c option is normally  set, and all others are normally reset.
Options may be  set on the command line with  a leading `+' sign.
The `-' command line option resets the c option.

Options may be set in the environment with an assignment, such as


        export ED=+cv


Options may  be set with  the `+' prefix  or  reset with  the `-'
prefix.




COHERENT Lexicon                                           Page 5




ed                           Command                           ed



***** See Also *****

commands, me, sed
_I_n_t_r_o_d_u_c_t_i_o_n _t_o _e_d

***** Diagnostics *****

ed usually prints only the diagnostic `?' on any error.  When the
verbose option  v is  specified, the `?'  is followed by  a brief
description of the nature of the error.















































COHERENT Lexicon                                           Page 6


