home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 278.lha / GnuSed / sed.man < prev    next >
Text File  |  1989-08-08  |  8KB  |  265 lines

  1.  
  2.  
  3.  
  4. SED(1)                    User Commands                     SED(1)
  5.  
  6.  
  7.  
  8. NAME
  9.      sed - stream editor
  10.  
  11. SYNOPSIS
  12.      sed [ -n ] [ -e script ] [ -f scriptfile ] [ files ]
  13.  
  14. DESCRIPTION
  15.      Sed copies the named files or the standard input to its
  16.      standard output, while performing certain operations speci-
  17.      fied in the command line script or in the file scriptfile.
  18.      If no filenames are specified, the default input is the
  19.      standard input.
  20.  
  21.      Sed cyclically reads in input lines and places them in the
  22.      pattern space.  The pattern space is selected by some or all
  23.      of the commands in the script, and acted upon by these com-
  24.      mands. The pattern space is then written to the output, and
  25.      the next input is read.
  26.  
  27.      The script (on the command line or in the script file) is
  28.      composed of one or more lines that have the following form:
  29.  
  30.      [ range ] function [ arguments ]
  31.  
  32.      The range refers to either a line address range or a regular
  33.      expression in the style of ed(1). The range selects which
  34.      input lines the function should act upon. If the range is
  35.      omitted, all input lines are selected.
  36.  
  37.      The line address is calculated sequentially from the first
  38.      file to last, in order. A line address range may be either a
  39.      single line number or two line numbers separated by a comma.
  40.      A single number selects that line number to act upon, and
  41.      two line numbers separated by a comma inclusively select all
  42.      lines between those two numbers.
  43.  
  44.      Regular expressions in sed differ from ed(1) regular expres-
  45.      sions in that the escape sequence `\n' matches a newline
  46.      embedded in the pattern space.  A $ character may also be
  47.      used to select the last line of input.
  48.  
  49.      The following list of sed functions are preceded by a number
  50.      indicating the maximum amount of line numbers valid in the
  51.      range of the function. A (1) would indicate that the func-
  52.      tion can only take effect after a certain line number and
  53.      not a range of line numbers, while a (2) would indicate that
  54.      either one line number or two are valid for the function.
  55.  
  56.      When a function takes a text argument, a newline in the text
  57.      may be escaped by placing a `\' character before it, allow-
  58.      ing multiline texts.
  59.  
  60.  
  61.  
  62.  
  63. GNU Project                1989 May 26                          1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SED(1)                    User Commands                     SED(1)
  71.  
  72.  
  73.  
  74.      Empty commands are ignored.
  75.  
  76.      A wfile or rfile argument to a function must be at the end
  77.      of a command line, and there must be exactly one space
  78.      between the command and the file name argument. There can be
  79.      at most 10 wfile and rfile arguments.  All wfile or rfile
  80.      arguments are created before any input lines are read.
  81.  
  82.      (1)a\
  83.      text
  84.           Append the text to the output after the current pattern
  85.           space.
  86.  
  87.      (2)b label
  88.           Branch to the label defined with the `:' command. An
  89.           empty label implies a branch to the end of the script.
  90.  
  91.      (2)c\
  92.      text
  93.           Change text.  The pattern space is unconditionally
  94.           deleted and the text is written to the output following
  95.           the range.
  96.  
  97.      (2)d Delete the pattern space.
  98.  
  99.      (2)D Delete the initial segment of the pattern space up to
  100.           and including the first newline.  (the pattern space
  101.           may contain more than one line of text -- see the `N'
  102.           command)
  103.  
  104.      (2)g Overwrite the pattern space with the contents of the
  105.           hold space.
  106.  
  107.      (2)G Append the contents of the hold space to the pattern
  108.           space.
  109.  
  110.      (2)h Hold the pattern space. The pattern space is copied
  111.           into the hold space.
  112.  
  113.      (2)H Append the pattern space to the hold space.
  114.  
  115.      (1)i\
  116.      text
  117.           Insert.  Write text to the output.
  118.  
  119.      (2)n Flush the pattern space to the output and read the next
  120.           input line into the pattern space.
  121.  
  122.      (2)N Append the next line of input to the pattern space,
  123.           inserting a newline character between them.
  124.  
  125.  
  126.  
  127.  
  128.  
  129. GNU Project                1989 May 26                          2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. SED(1)                    User Commands                     SED(1)
  137.  
  138.  
  139.  
  140.      (2)p Print.  Write a copy of the pattern space to the out-
  141.           put.
  142.  
  143.      (2)P Write a copy of the pattern space up to and including
  144.           the first newline to the output.
  145.  
  146.      (1)q Quit and do not start a new cycle.
  147.  
  148.      (2)r rfile
  149.           Read the contents of rfile and write them to the out-
  150.           put.
  151.  
  152.      (2)s/regular expression/replacement/flags
  153.           Search for the regular expression in the pattern space
  154.           and replace it with the replacement string.  Any char-
  155.           acter may be used as a delimiter instead of the `/'.
  156.           The flags argument may be any number of the following:
  157.  
  158.           g    Globally substitute the replacement for the regu-
  159.                lar expression. Normally, only the first match is
  160.                found, but g forces matching of all occurances.
  161.  
  162.           p    Print the pattern space if a replacement was made.
  163.  
  164.           w wfile
  165.                Write the pattern space to the end of wfile if a
  166.                replacement was made. This must be the last flag
  167.                argument if it is used.
  168.  
  169.      (2)t label
  170.           Test.  If a substitution was made since the last time
  171.           an input line was read into the pattern space, or since
  172.           the last `t' command, command branches to the label. An
  173.           empty label means to branch to the end of the script.
  174.  
  175.      (2)w wfile
  176.           Write the pattern space to the file wfile.
  177.  
  178.      (2)x Exchange the contents of the pattern and hold spaces.
  179.  
  180.      (2)y/string1/string2/
  181.           Yank all characters in string1 and replace them with
  182.           the corresponding characters in string2, which should
  183.           be of equal length as string1.
  184.  
  185.      (2)! function
  186.           Apply the function to those lines not selected by the
  187.           command.
  188.  
  189.      (0): label
  190.           Declare a label for `b' and `t' commands to branch to.
  191.  
  192.  
  193.  
  194.  
  195. GNU Project                1989 May 26                          3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. SED(1)                    User Commands                     SED(1)
  203.  
  204.  
  205.  
  206.      (1)= Write the current line number to the output.
  207.  
  208.      (2){ Perform multiple commands on the range. The `{' charac-
  209.           ter is followed by one or more commands to perform on
  210.           the pattern space. A '}' character terminates the list
  211.           of commands.
  212.  
  213. OPTIONS
  214.      -n      suppress the default output
  215.  
  216.      -e      indicates that the next argument is a script. Useful
  217.              for scripts starting with a - character.
  218.  
  219.      -f      indicates that the following argument is a file con-
  220.              taining a script of commands to Sed.
  221.  
  222. SEE ALSO
  223.      ed(1), grep(1), awk(1), lex(1)
  224.  
  225. AVAILABILITY
  226.      GNU sed is free; anyone may redistribute copies of sed to
  227.      anyone under the terms stated in the GNU General Public
  228.      License, a copy of which may be found in each copy of GNU
  229.      Emacs.  See also the comment at the beginning of the source
  230.      code file sed.c.
  231.  
  232.      Copies of GNU sed may sometimes be received packaged with
  233.      distributions of Unix systems, but it is never included in
  234.      the scope of any license covering those systems.  Such
  235.      inclusion violates the terms on which distribution is per-
  236.      mitted.  In fact, the primary purpose of the General Public
  237.      License is to prohibit anyone from attaching any other res-
  238.      trictions to redistribution of any of the Free Software
  239.      Foundation programs.
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261. GNU Project                1989 May 26                          4
  262.  
  263.  
  264.  
  265.