[0m


ED(1V)		    UNIX Programmer's Manual		   ED(1V)



[1mNAME
     [0med, red - text editor

[1mSYNOPSIS
     /usr/5bin/ed [0m[[1m-[0m] [[1m-p [0m_s_t_r_i_n_g] [_f_i_l_e]
     [1m/usr/5bin/red [0m[[1m-[0m] [[1m-p [0m_s_t_r_i_n_g] [_f_i_l_e]

[1mDESCRIPTION
     [0m_E_d is the standard text editor.

     If a _f_i_l_e argument is given, _e_d simulates an _e command (see
     below) on the named file; that is to say, the file is read
     into _e_d'_s buffer so that it can be edited.  The optional [1m-
     [0msuppresses the printing of explanatory output and should be
     used when the standard input is an editor script.

     The [1m-p [0moption allows specification of a prompt string.

     _E_d operates on a copy of any file it is editing; changes
     made in the copy have no effect on the file until a _w
     (write) command is given.	The copy of the text being edited
     resides in a temporary file called the _b_u_f_f_e_r.

     _R_e_d is a restricted version of _e_d which only allows editing
     of files in the current directory and prevents the execution
     of commands via !_c_o_m_m_a_n_d.

     Commands to _e_d have a simple and regular structure: zero or
     more _a_d_d_r_e_s_s_e_s followed by a single character _c_o_m_m_a_n_d, pos-
     sibly followed by parameters to the command.  These
     addresses specify one or more lines in the buffer.  Missing
     addresses are supplied by default.

     In general, only one command may appear on a line.  Certain
     commands allow the addition of text to the buffer.  While _e_d
     is accepting text, it is said to be in _i_n_p_u_t _m_o_d_e. In this
     mode, no commands are recognized; all input is merely col-
     lected.  Input mode is left by typing a period `[1m.[0m' alone at
     the beginning of a line.

     _E_d supports a limited form of _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n notation.
     A regular expression specifies a set of strings of charac-
     ters.  A member of this set of strings is said to be _m_a_t_c_h_e_d
     by the regular expression.  In the following specification
     for regular expressions the word `character' means any char-
     acter but newline.

     1.   Any character except a special character matches
	  itself.  Special characters are the regular expression
	  delimiter plus \[[1m.  [0mand sometimes ^*$.

     2.   A [1m. [0mmatches any character.



Printed 31/1/92     Revision 1.1 of 10/10/90			1






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



     3.   A \ followed by any character except a digit or ()
	  matches that character.

     4.   A nonempty string _s bracketed [_s] (or [^_s]) matches any
	  character in (or not in) _s. In _s, \ has no special
	  meaning, and ] may only appear as the first letter.  A
	  substring _a-_b, with _a and _b in ascending ASCII order,
	  stands for the inclusive range of ASCII characters.

     5.   A regular expression of form 1-4 followed by * matches
	  a sequence of 0 or more matches of the regular expres-
	  sion.

     6.   A regular expression, _x, of form 1-8, bracketed \(_x\)
	  matches what _x matches.

     7.   A \ followed by a digit _n matches a copy of the string
	  that the bracketed regular expression beginning with
	  the _nth \( matched.

     8.   A regular expression of form 1-8, _x, followed by a reg-
	  ular expression of form 1-7, _y matches a match for _x
	  followed by a match for _y, with the _x match being as
	  long as possible while still permitting a _y match.

     9.   A regular expression of form 1-8 preceded by ^ (or fol-
	  lowed by $), is constrained to matches that begin at
	  the left (or end at the right) end of a line.

     10.  A regular expression of form 1-9 picks out the longest
	  among the leftmost matches in a line.

     11.  An empty regular expression stands for a copy of the
	  last regular expression encountered.

     Regular expressions are used in addresses to specify lines
     and in one command (see _s below) to specify a portion of a
     line which is to be replaced.  If it is desired to use one
     of the regular expression metacharacters as an ordinary
     character, that character may be preceded by `\'.	This also
     applies to the character bounding the regular expression
     (often `/') and to `\' itself.

     To understand addressing in _e_d it is necessary to know that
     at any time there is a _c_u_r_r_e_n_t _l_i_n_e. Generally speaking, the
     current line is the last line affected by a command; how-
     ever, the exact effect on the current line is discussed
     under the description of the command.  Addresses are con-
     structed as follows.

     1.   The character `[1m.[0m' addresses the current line.




Printed 31/1/92     Revision 1.1 of 10/10/90			2






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



     2.   The character `$' addresses the last line of the
	  buffer.

     3.   A decimal number _n addresses the _n-th line of the
	  buffer.

     4.   `'_x' addresses the line marked with the name _x, which
	  must be a lower-case letter.	Lines are marked with the
	  _k command described below.

     5.   A regular expression enclosed in slashes `/' addresses
	  the line found by searching forward from the current
	  line and stopping at the first line containing a string
	  that matches the regular expression.	If necessary the
	  search wraps around to the beginning of the buffer.

     6.   A regular expression enclosed in queries `?' addresses
	  the line found by searching backward from the current
	  line and stopping at the first line containing a string
	  that matches the regular expression.	If necessary the
	  search wraps around to the end of the buffer.

     7.   An address followed by a plus sign `+' or a minus sign
	  `-' followed by a decimal number specifies that address
	  plus (resp. minus) the indicated number of lines.  The
	  plus sign may be omitted.

     8.   If an address begins with `+' or `-' the addition or
	  subtraction is taken with respect to the current line;
	  e.g. `-5' is understood to mean `[1m.[0m-5'.

     9.   If an address ends with `+' or `-', then 1 is added
	  (resp. subtracted).  As a consequence of this rule and
	  rule 8, the address `-' refers to the line before the
	  current line.  Moreover, trailing `+' and `-' charac-
	  ters have cumulative effect, so `--' refers to the
	  current line less 2.

     10.  For convenience, a comma `,' stands for the address
	  `1,$' and a semicolon `;' stands for `.,$'

     Commands may require zero, one, or two addresses.	Commands
     which require no addresses regard the presence of an address
     as an error.  Commands which accept one or two addresses
     assume default addresses when insufficient are given.  If
     more addresses are given than such a command requires, the
     last one or two (depending on what is accepted) are used.

     Addresses are separated from each other typically by a comma
     `[1m,[0m'.  They may also be separated by a semicolon `[1m;[0m'.  In
     this case the current line `[1m.[0m' is set to the previous
     address before the next address is interpreted.  This



Printed 31/1/92     Revision 1.1 of 10/10/90			3






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



     feature can be used to determine the starting line for for-
     ward and backward searches (`/', `?').  The second address
     of any two-address sequence must correspond to a line fol-
     lowing the line corresponding to the first address.

     In the following list of _e_d commands, the default addresses
     are shown in parentheses.	The parentheses are not part of
     the address, but are used to show that the given addresses
     are the default.

     As mentioned, it is generally illegal for more than one com-
     mand to appear on a line.	However, most commands may be
     suffixed by `p' or by `l', in which case the current line is
     either printed or listed respectively in the way discussed
     below.  Commands may also be suffixed by `n', meaning the
     output of the command is to be line numbered.  These suf-
     fixes may be combined in any order.

     ([1m.[0m)a
     <text>
     [1m.
	  [0mThe append command reads the given text and appends it
	  after the addressed line.  `[1m.[0m' is left on the last line
	  input, if there were any, otherwise at the addressed
	  line.  Address `0' is legal for this command; text is
	  placed at the beginning of the buffer.

     ([1m.[0m, [1m.[0m)c
     <text>
     [1m.
	  [0mThe change command deletes the addressed lines, then
	  accepts input text which replaces these lines.  `[1m.[0m' is
	  left at the last line input; if there were none, it is
	  left at the line preceding the deleted lines.

     ([1m.[0m, [1m.[0m)d
	  The delete command deletes the addressed lines from the
	  buffer.  The line originally after the last line
	  deleted becomes the current line; if the lines deleted
	  were originally at the end, the new last line becomes
	  the current line.

     e filename
	  The edit command causes the entire contents of the
	  buffer to be deleted, and then the named file to be
	  read in.  `[1m.[0m' is set to the last line of the buffer.
	  The number of characters read is typed.  `filename' is
	  remembered for possible use as a default file name in a
	  subsequent _r or _w command.  If `filename' is missing,
	  the remembered name is used.	If the `filename' begins
	  with an exclamation mark, `!', then the rest of the
	  line is executed as a shell command whose output is



Printed 31/1/92     Revision 1.1 of 10/10/90			4






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



	  read into the buffer.  In this case, the command is not
	  remembered as the default filename.

     E filename
	  This command is the same as _e, except that no diagnos-
	  tic results when no _w has been given since the last
	  buffer alteration.

     f filename
	  The filename command prints the currently remembered
	  file name.  If `filename' is given, the currently
	  remembered file name is changed to `filename'.

     (1,$)g/regular expression/command list
	  In the global command, the first step is to mark every
	  line which matches the given regular expression.  Then
	  for every such line, the given command list is executed
	  with `[1m.[0m' initially set to that line.	A single command
	  or the first of multiple commands appears on the same
	  line with the global command.  All lines of a multi-
	  line list except the last line must be ended with `\'.
	  _A, _i, and _c commands and associated input are permit-
	  ted; the `[1m.[0m' terminating input mode may be omitted if
	  it would be on the last line of the command list.  The
	  commands _g, _G, _v and _V are not permitted in the command
	  list.

     (1,$)G/regular expression/
	  In the interactive global command, the first step is to
	  mark every line that matches the given regular expres-
	  sion.  Then, for every such line, the line is printed,
	  `.' is set to that line, and any one command may be
	  input and executed.  (Exceptions: the _a, _c, _i, _g, _G, _v,
	  and _V commands are not allowed.) A newline acts as a
	  null command, an `&' causes the last command to be
	  repeated on this line.  The _G command may be terminated
	  by sending an interrupt signal.

     h	  The help command gives a short diagnostic message
	  explaining the last error.

     H	  This causes _e_d to enter diagnostic mode, in which mes-
	  sages are printed for all subsequent error conditions.
	  It will also explain the previous diagnostic, if there
	  was one.  Subsequent _H commands toggle diagnostic mes-
	  sages off and on.  When off, _e_d reports all error con-
	  ditions by printing a question mark, `?'.

     ([1m.[0m)i
     <text>
     [1m.
	  [0mThis command inserts the given text before the



Printed 31/1/92     Revision 1.1 of 10/10/90			5






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



	  addressed line.  `[1m.[0m' is left at the last line input,
	  or, if there were none, at the line before the
	  addressed line.  This command differs from the _a com-
	  mand only in the placement of the text.

     ([1m.[0m, [1m.[0m+1)j
	  This command joins the addressed lines into a single
	  line; intermediate newlines simply disappear.  `[1m.[0m' is
	  left at the resulting line.

     ( [1m. [0m)k_x
	  The mark command marks the addressed line with name _x,
	  which must be a lower-case letter.  The address form
	  `'_x' then addresses this line.

     ([1m.[0m, [1m.[0m)l
	  The list command prints the addressed lines in an unam-
	  biguous way: non-graphic characters are printed in
	  octal, backspaces and tabs are represented as `<' and
	  `>' respectively, and long lines are folded.	The _l
	  command may be placed on the same line after any non-
	  i/o command.

     ([1m.[0m, [1m.[0m)m_a
	  The move command repositions the addressed lines after
	  the line addressed by _a.  The last of the moved lines
	  becomes the current line.  It is an error if address _a
	  falls within the range of the moved lines.

     ([1m.[0m, [1m.[0m)n
	  The number command prints the addressed lines, preced-
	  ing each with its line number and a tab.  `[1m.[0m' is left
	  at the last line printed.  The _n command may be
	  appended to any non-i/o command.

     ([1m.[0m, [1m.[0m)p
	  The print command prints the addressed lines.  `[1m.[0m' is
	  left at the last line printed.  The _p command may be
	  placed on the same line after any non-i/o command.

     P	  Turns prompting alternately on and off.  When on, the
	  editor will prompt for commands with an asterisk, `*'.
	  This mode is initially off.

     q	  The quit command causes _e_d to exit.  No automatic write
	  of a file is done.

     Q	  This command is the same as _q, except that no diagnos-
	  tic results when no _w has been given since the last
	  buffer alteration.

     ($)r filename



Printed 31/1/92     Revision 1.1 of 10/10/90			6






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



	  The read command reads in the given file after the
	  addressed line.  If no file name is given, the remem-
	  bered file name, if any, is used (see _e and _f com-
	  mands).  The file name is remembered if there was no
	  remembered file name already.  Address `0' is legal for
	  _r and causes the file to be read at the beginning of
	  the buffer.  If the read is successful, the number of
	  characters read is typed.  `[1m.[0m' is left at the last line
	  read in from the file.  If the _f_i_l_e_n_a_m_e starts with an
	  exclamation mark, `!', then the rest of the line is
	  executed as a shell command whose output is read into
	  the buffer.  Such a command is not remembered as the
	  current filename.

     ( [1m.[0m, [1m.[0m)s/regular expression/replacement/	    or,
     ( [1m.[0m, [1m.[0m)s/regular expression/replacement/g	     or,
     ( [1m.[0m, [1m.[0m)s/regular expression/replacement/_n	     n=1-512
	  The substitute command searches each addressed line for
	  an occurrence of the specified regular expression.  On
	  each line in which a match is found, all matched
	  strings are replaced by the replacement specified, if
	  the global replacement indicator `g' appears after the
	  command.  If a number _n appears in place of the `g',
	  then only the _nth occurrence of the matched string is
	  replaced on each addressed line.  Otherwise only the
	  first occurrence of the matched string on each
	  addressed line is replaced.  It is an error for the
	  substitution to fail on all addressed lines.	Any punc-
	  tuation character may be used instead of `/' to delimit
	  the regular expression and the replacement.  `[1m.[0m' is
	  left at the last line substituted.

	  An ampersand `&' appearing in the replacement is
	  replaced by the string matching the regular expression.
	  The special meaning of `&' in this context may be
	  suppressed by preceding it by `\'.  The characters `_\_n'
	  where _n is a digit, are replaced by the text matched by
	  the _n-th regular subexpression enclosed between `\('
	  and `\)'.  When nested, parenthesized subexpressions
	  are present, _n is determined by counting occurrences of
	  `\(' starting from the left.	When the replacement
	  string consists only of a single percent sign, `%', the
	  replacement string from the last _s command is re-used.
	  The `%' loses its special meaning if the replacement
	  string is more than one character or if it is escaped
	  with a backslash.

	  Lines may be split by substituting new-line characters
	  into them.  The new-line in the replacement string must
	  be escaped by preceding it by `\'.

     ([1m.[0m, [1m.[0m)t_a



Printed 31/1/92     Revision 1.1 of 10/10/90			7






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



	  This command acts just like the _m command, except that
	  a copy of the addressed lines is placed after address _a
	  (which may be 0).  `[1m.[0m' is left on the last line of the
	  copy.

     ([1m.[0m, [1m.[0m)u
	  The undo command restores the buffer to it's state
	  before the most recent buffer modifying command.
	  Buffer modifying commands are _a, _c, _d, _g, _i, _j, _m, _r,
	  _s, _t, _v, _G and _V. Undo is its own inverse.

     (1, $)v/regular expression/command list
	  This command is the same as the global command _g except
	  that the command list is executed _g with `[1m.[0m' initially
	  set to every line _e_x_c_e_p_t those matching the regular
	  expression.

     (1, $)V/regular expression/
	  This command is the interactive version of the _v com-
	  mand; see the descriptions of _v and _G for details.

     (1, $)w filename
	  The write command writes the addressed lines onto the
	  given file.  If the file does not exist, it is created.
	  The file name is remembered if there was no remembered
	  file name already.  If no file name is given, the
	  remembered file name, if any, is used (see _e and _f com-
	  mands).  `[1m.[0m' is unchanged.  If the command is success-
	  ful, the number of characters written is printed.  If
	  _f_i_l_e_n_a_m_e begins with an exclamation mark, `!', then the
	  rest of the line is excecuted as a shell command whose
	  standard input is the addressed lines.  Such a command
	  is not remembered as the current filename.

     ($)= The line number of the addressed line is typed.  `[1m.[0m' is
	  unchanged by this command.

     !<shell command>
	  The remainder of the line after the `!' is sent to
	  _s_h(1) to be interpreted as a command.  Within the com-
	  mand, the unescaped character `%' is replaced with the
	  current filename.  If the first character of the com-
	  mand is `!' it is replaced with the text of the previ-
	  ous shell command.  Thus `!!' will repeat the last com-
	  mand.  If an expansion is done the expanded line is
	  echoed.  The `!' command does not alter the value of
	  `.'.

     ([1m.[0m+1,[1m.[0m+1)<newline>
	  An address alone on a line causes the addressed line to
	  be printed.  A blank line alone is equivalent to
	  `.+1p'; it is useful for stepping through text.  If two



Printed 31/1/92     Revision 1.1 of 10/10/90			8






ED(1V)		    UNIX Programmer's Manual		   ED(1V)



	  addresses are present with no intervening semicolon, _e_d
	  prints the range of lines.  If they are separated by a
	  semicolon, the second line is printed.

     If _e_d receives an interrupt signal, it prints a `?' and
     returns to its command level.

     If _e_d receives a SIGHUP signal, the current buffer contents
     is saved in the file _e_d._h_u_p.

     If the closing delimiter of a regular expression would be
     the last character before a newline, it may be omitted.  In
     this case an automatic _p suffix is assumed, causing the
     addressed line to be printed.

     If the buffer has changed since the last _w command that
     wrote the entire buffer, _e_d warns the user if an attempt is
     made to destroy the buffer with the _e or _q commands.  It
     prints `?' and awaits further commands.  A second _e or _q
     command at this point will take effect.  The [1m- [0mcommand line
     option disables this feature.

[1mFILES
     [0m/var/tmp/e*
     ed.hup: work is saved here if terminal hangs up

[1mSEE ALSO
     [0mB. W. Kernighan, _A _T_u_t_o_r_i_a_l _I_n_t_r_o_d_u_c_t_i_o_n _t_o _t_h_e _E_D _T_e_x_t _E_d_i_-
     _t_o_r
     B. W. Kernighan, _A_d_v_a_n_c_e_d _e_d_i_t_i_n_g _o_n _U_N_I_X
     ex(1), sed(1), crypt(1)

[1mDIAGNOSTICS
     [0m`?name' for inaccessible file;
     `?' for other errors.
     Use the `h' and `H' commands for self-explanatory messages.



















Printed 31/1/92     Revision 1.1 of 10/10/90			9



[0m