

sed                          Command                          sed




Stream editor

sseedd [ -nn ] [-ee _c_o_m_m_a_n_d_s] [-ff _s_c_r_i_p_t] ... _f_i_l_e ...

sed is  a non-interactive text editor.  It  reads input from each
file, or from  the standard input if no file  is named.  It edits
the input  according to commands  given in the  commands argument
and the  script files.  It  then writes the edited  text onto the
standard output.

sed  resembles the  interactive editor ed,  but its  operation is
fundamentally different.  sed  normally edits one line at a time,
so it may be used to  edit very large files.  After it constructs
a list  of commands from  its commands and  script arguments, sed
reads the  input one line at  a time into a  work area.  Then sed
executes  each command  that applies  to  the line,  as explained
below.  Finally,  it copies the work area  to the standard output
(unless the  -n option is  specified), erases the  work area, and
reads the next input line.

***** Line Identifiers *****

sed  identifies input  lines by  integer line  numbers, beginning
with  one for  the first  line of the  first file  and continuing
through each successive  file.  The following special forms iden-
tify lines:

nn    A decimal number n addresses the nth line of the input.

.    A period `.' addresses the current input line.

$    A dollar sign `$' addresses the last line of input.

/ppaatttteerrnn/
     A pattern  enclosed within slashes addresses  the next input
     line that  contains pattern.  Patterns,  also called regular
     expressions, are described in detail below.

***** Commands *****

Each command  must be on  a separate line.  Most  commands may be
optionally preceded  by a line identifier  (abbreviated as [n] in
the command  summary below) or by  two-line identifiers separated
by  a comma  (abbreviated  as [n[,m]]).   If  no line  identifier
precedes a command, sed  applies the command to every input line.
If one  line identifier precedes a command,  sed applies the com-
mand to each input  line selected by the identifier.  If two-line
identifiers precede  a command, sed  begins to apply  the command
when an  input line is  selected by the first,  and continues ap-
plying it through an input line selected by the second.

sed recognizes the following commands:




COHERENT Lexicon                                           Page 1




sed                          Command                          sed



[_n]= Output the current input line number.

[_n[,_m]]!_c_o_m_m_a_n_d
     Apply command to each line not identified by [n[,m]].

[_n[,_m]]{_c_o_m_m_a_n_d...}
     Execute each enclosed command on the given lines.

:_l_a_b_e_l
     Define label for use in branch or test command.

[_n]aa\
     Append new text after given line.  New text is terminated by
     any line not ending in `\'.

bb [_l_a_b_e_l]
     Branch to label, which must be defined in a `:' command.  If
     label is omitted, branch to end of command script.

[_n[,_m]]cc\
     Change specified lines to new text and proceed with next in-
     put line.  New text is  terminated by any line not ending in
     `\'.

[_n[,_m]]dd
     Delete specified lines and proceed with next input line.

[_n[,_m]]DD
     Delete first  line in work area and  proceed with next input
     line.

[_n[,_m]]gg
     Copy secondary  work area to work  area, destroying previous
     contents.

[_n[,_m]]GG
     Append secondary work area to work area.

[_n[,_m]]hh
     Copy work area  to secondary work area,  destroying previous
     contents.

[_n[,_m]]HH
     Append work area to secondary work area.

[_n]ii\
     Insert new  text before given line.   New text is terminated
     by any line not ending in `\'.

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

[_n[,_m]]nn
     Print the work area and replace it with the next input line.



COHERENT Lexicon                                           Page 2




sed                          Command                          sed



[_n[,_m]]NN
     Append next input line preceded by a newline to work area.

[_n[,_m]]pp
     Print work area.

[_n[,_m]]PP
     Print first line of work area.

[_n]qq Quit without reading any more input.

[_n]rr _f_i_l_e
     Copy file to output.

[_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][ww _f_i_l_e]
     Search for  pattern1 and substitute pattern2  for kth occur-
     rence (default, first).   If optional g is given, substitute
     all occurrences.   If optional p is  given, print the resul-
     ting  line.  If  optional w is  given, append  the resulting
     line to file.  Patterns are described in detail below.

[_n[,_m]]tt[_l_a_b_e_l]
     Test  if substitutions  have been  made.   If so,  branch to
     label, which must be defined  in a `:' command.  If label is
     omitted, branch to end of command script.

[_n[,_m]]ww _f_i_l_e
     Append lines to file.

[_n[,_m]] xx
     Exchange the work area and the secondary work area.

[_n[,_m]]yy/_c_h_a_r_s/_r_e_p_l_a_c_e_m_e_n_t_s/
     Translate characters  in chars to  the corresponding charac-
     ters in replacements.

***** Patterns *****

Substitution commands and  search specifications may include pat-
terns, also  called regular expressions.   Pattern specifications
are identical to those  of ed, except that the special characters
`\nn' match a newline character in the input.

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.

\nn   Match the newline character.

.    Match any character except newline.



COHERENT Lexicon                                           Page 3




sed                          Command                          sed



*    Match zero or more repetitions of preceding character.

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

[^_c_h_a_r_s]
     Match any character  except one of the enclosed chars.  Ran-
     ges 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.

In addition, the replacement part pattern2 of the substitute com-
mand 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 *****

sed recognizes the following options:

-ee   Next argument gives commands.

-ff   Next argument gives file name of command script.

-nn   Output lines only when explicit p or P commands are given.

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

commands, ed





















COHERENT Lexicon                                           Page 4


