COHERENT manpages

This page displays the COHERENT manpage for sed [Stream editor].

List of available manpages
Index


sed -- Command

Stream editor
sed [ -n ] [-e command] [-f script] ... file ...

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 identify lines:

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.

/pattern/
        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 command 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  applying it through an
input line selected by the second.

sed recognizes the following commands:

[n]=    Output the current input line number.

[n[,m]]!command
        Apply command to each line not identified by [n[,m]].

[n[,m]]{command...}
        Execute each enclosed command on the given lines.

:label  Define label for use in branch or test command.

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

b [label]
        Branch to label, which must be  defined in a `:' command.  If label
        is omitted, branch to end of command script.

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

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

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

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

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

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

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

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

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

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

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

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

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

[n]q    Quit without reading any more input.

[n]r file
        Copy file to output.

[n[,m]]s[k]/pattern1/pattern2/[g][p][w file]
        Search for  pattern1  and substitute  pattern2  for kth  occurrence
        (default,  first).   If   optional  g  is   given,  substitute  all
        occurrences.  If optional p is given, print the resulting line.  If
        optional w is  given, append the  resulting line to  file. Patterns
        are described in detail below.

[n[,m]]t[label]
        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 file
        Append lines to file.

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

[n[,m]]y/chars/replacements/
        Translate characters  in chars to  the corresponding  characters in
        replacements.

Patterns

Substitution commands and  search specifications may include patterns, also
called regular  expressions. Pattern specifications are  identical to those
of ed, except that the special characters `\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      Match the newline character.

.       Match any character except newline.

*       Match zero or more repetitions of preceding character.

[chars]
        Match any one  of the enclosed  chars. Ranges of  letters or digits
        may be indicated using `-'.

[^chars]
        Match any  character except  one of the  enclosed chars.  Ranges of
        letters or digits may be indicated using `-'.

\c      Disregard special meaning of character c.

\(pattern\)
        Delimit substring pattern; for use with \d, described below.

In addition,  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

sed recognizes the following options:

-e   Next argument  gives a sed command.  sed's command  line can have more
     than one -e option.

-f   Next argument gives file name of command script.

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

Limits

The COHERENT  implementation of sed sets the following  limits on input and
output:

     Characters per input record512
     Characters per output record512
     Characters per field     512

See Also

commands,
ed,
elvis,
ex,
me,
vi
Introduction to the sed Stream Editor