home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / editor / sed / sed.man < prev    next >
Text File  |  1994-01-31  |  7KB  |  193 lines

  1. NAME
  2.      sed - stream text editor
  3.  
  4. SYNTAX
  5.      sed [-n] [-e script] [-f sfile] [file...]
  6.  
  7. DESCRIPTION
  8.      The sed command copies the named files (standard input
  9.      default) to the standard output, edited according to a
  10.      script of commands.  The -f option causes the script to be
  11.      taken from file sfile; these options accumulate.  If there
  12.      is just one -e option and no -f's, the flag -e may be omit-
  13.      ted.  The -n option suppresses the default output.
  14.  
  15.      A script consists of editing commands, one per line, of the
  16.      following form:
  17.  
  18.           [address [, address] ] function [arguments]
  19.  
  20.      In normal operation sed cyclically copies a line of input
  21.      into a pattern space (unless there is something left after a
  22.      `D' command), applies in sequence all commands whose
  23.      addresses select that pattern space, and at the end of the
  24.      script copies the pattern space to the standard output
  25.      (except under -n) and deletes the pattern space.
  26.  
  27.      An address is either a decimal number that counts input
  28.      lines cumulatively across files, a `$' that addresses the
  29.      last line of input, or a context address, `/regular expres-
  30.      sion/', in the style of ed(1) modified thus:
  31.  
  32.           The escape sequence `\n' matches a new line embedded in
  33.           the pattern space.
  34.  
  35.      A command line with no addresses selects every pattern
  36.      space.
  37.  
  38.      A command line with one address selects each pattern space
  39.      that matches the address.
  40.  
  41.      A command line with two addresses selects the inclusive
  42.      range from the first pattern space that matches the first
  43.      address through the next pattern space that matches the
  44.      second.  (If the second address is a number less than or
  45.      equal to the line number first selected, only one line is
  46.      selected.) Thereafter the process is repeated, looking again
  47.      for the first address.
  48.  
  49.      Editing commands can be applied only to non-selected pattern
  50.      spaces by use of the negation function `!' (below).
  51.  
  52.      In the following list of functions the maximum number of
  53.      permissible addresses for each function is indicated in
  54.      parentheses.
  55.  
  56.      An argument denoted text consists of one or more lines, all
  57.      but the last of which end with `\' to hide the new line.
  58.      Backslashes in text are treated like backslashes in the
  59.      replacement string of an `s' command, and may be used to
  60.      protect initial blanks and tabs against the stripping that
  61.      is done on every script line.
  62.  
  63.      An argument denoted rfile or wfile must terminate the com-
  64.      mand line and must be preceded by exactly one blank.  Each
  65.      wfile is created before processing begins.  There can be at
  66.      most 10 distinct wfile arguments.
  67.  
  68.      (1)a\
  69.      text
  70.              Append.  Place text on the output before reading the
  71.              next input line.
  72.  
  73.      (2)b label
  74.              Branch to the `:' command bearing the label.  If
  75.              label is empty, branch to the end of the script.
  76.  
  77.      (2)c\
  78.      text
  79.              Change.  Delete the pattern space.  With 0 or 1
  80.              address or at the end of a 2-address range, place
  81.              text on the output.  Start the next cycle.
  82.  
  83.      (2)d    Delete the pattern space.  Start the next cycle.
  84.  
  85.      (2)D    Delete the initial segment of the pattern space
  86.              through the first new line.  Start the next cycle.
  87.  
  88.      (2)g    Replace the contents of the pattern space by the
  89.              contents of the hold space.
  90.  
  91.      (2)G    Append the contents of the hold space to the pattern
  92.              space.
  93.  
  94.      (2)h    Replace the contents of the hold space by the con-
  95.              tents of the pattern space.
  96.  
  97.      (2)H    Append the contents of the pattern space to the hold
  98.              space.
  99.  
  100.      (1)i\
  101.      text
  102.              Insert.  Place text on the standard output.
  103.  
  104.      (2)l    Print as C string with escape character constants for
  105.          non-printables.
  106.  
  107.      (2)n    Copy the pattern space to the standard output.
  108.              Replace the pattern space with the next line of
  109.              input.
  110.  
  111.      (2)N    Append the next line of input to the pattern space
  112.              with an embedded new line.  (The current line number
  113.              changes.)
  114.  
  115.      (2)p    Print.  Copy the pattern space to the standard out-
  116.              put.
  117.  
  118.      (2)P    Copy the initial segment of the pattern space
  119.              through the first new line to the standard output.
  120.  
  121.      (1)q    Quit.  Branch to the end of the script.  Do not
  122.              start a new cycle.
  123.  
  124.      (2)r rfile
  125.              Read the contents of rfile.  Place them on the out-
  126.              put before reading the next input line.
  127.  
  128.      (2)s/regular expression/replacement/flags
  129.              Substitute the replacement string for instances of
  130.              the regular expression in the pattern space.  Any
  131.              character may be used instead of `/'.  For a more
  132.              complete description see ed(1).  The flags is zero
  133.              or more of
  134.  
  135.              g       Global.  Substitute for all nonoverlapping
  136.                      instances of the regular expression rather
  137.                      than just the first one.
  138.  
  139.              p       Print the pattern space if a replacement was
  140.                      made.
  141.  
  142.              w wfile Write.  Append the pattern space to wfile if
  143.                      a replacement was made.
  144.  
  145.      (2)t label
  146.              Test.  Branch to the `:' command bearing the label
  147.              if any substitutions have been made since the most
  148.              recent reading of an input line or execution of a
  149.              `t'.  If label is empty, branch to the end of the
  150.              script.
  151.  
  152.      (2)w wfile
  153.              Write.  Append the pattern space to wfile.
  154.  
  155.      (2)x    Exchange the contents of the pattern and hold
  156.              spaces.
  157.  
  158.      (2)y/string1/string2/
  159.              Transform.  Replace all occurrences of characters in
  160.              string1 with the corresponding character in string2.
  161.              The lengths of string1 and string2 must be equal.
  162.  
  163.      (2)! function
  164.              Don't.  Apply the function (or group, if function is
  165.              `{') only to lines not selected by the address(es).
  166.  
  167.      (0): label
  168.              This command does nothing; it bears a label for `b'
  169.              and `t' commands to branch to.
  170.  
  171.      (1)=    Place the current line number on the standard output
  172.              as a line.
  173.  
  174.      (2){    Execute the following commands through a matching
  175.              `}' only when the pattern space is selected.
  176.  
  177.      (0)     An empty command is ignored.
  178.  
  179. OPTIONS
  180.      -e script
  181.              Uses specified file as input file of commands to be
  182.              executed.
  183.  
  184.      -f sfile
  185.              Uses specified file as input file of commands to be
  186.              executed.  May be used with -e option to indicate
  187.              two script files.
  188.  
  189.      -n      Suppresses all normal output.
  190.  
  191. SEE ALSO
  192.      awk(1), ed(1), grep(1), lex(1)
  193.