home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 213b.lha / Sed / ed.man < prev    next >
Text File  |  1996-02-14  |  21KB  |  595 lines

  1.  
  2.  
  3.  
  4. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  5.  
  6.  
  7.  
  8. NAME
  9.      ed - text editor
  10.  
  11. ORIGIN
  12.      OSx
  13.  
  14. SYNOPSIS
  15.      ed [ - ] [ -x ] [ name ]
  16.  
  17. DESCRIPTION
  18.      Ed is the standard text editor.
  19.  
  20.      If a name argument is given, ed simulates an e command (see
  21.      below) on the named file; that is to say, the file is read
  22.      into ed's buffer so that it can be edited.  If -x is
  23.      present, an x command is simulated first to handle an
  24.      encrypted file.  The optional - suppresses the printing of
  25.      explanatory output and should be used when the standard
  26.      input is an editor script.
  27.  
  28.      Ed operates on a copy of any file it is editing; changes
  29.      made in the copy have no effect on the file until a w
  30.      (write) command is given.  The copy of the text being edited
  31.      resides in a temporary file called the buffer.
  32.  
  33.      Commands to ed have a simple and regular structure: zero or
  34.      more addresses followed by a single character command, pos-
  35.      sibly followed by parameters to the command.  These
  36.      addresses specify one or more lines in the buffer.  Missing
  37.      addresses are supplied by default.
  38.  
  39.      In general, only one command may appear on a line.  Certain
  40.      commands allow the addition of text to the buffer.  While ed
  41.      is accepting text, it is said to be in input mode. In this
  42.      mode, no commands are recognized; all input is merely col-
  43.      lected.  Input mode is left by typing a period `.' alone at
  44.      the beginning of a line.
  45.  
  46.      Ed supports a limited form of regular expression notation.
  47.      A regular expression specifies a set of strings of charac-
  48.      ters.  A member of this set of strings is said to be matched
  49.      by the regular expression.  In the following specification
  50.      for regular expressions the word `character' means any char-
  51.      acter but newline.
  52.  
  53.      1.   Any character except a special character matches
  54.           itself.  Special characters are the regular expression
  55.           delimiter plus \[.  and sometimes ^*$.
  56.  
  57.      2.   A . matches any character.
  58.  
  59.      3.   A \ followed by any character except a digit or ()
  60.  
  61.  
  62.  
  63. Printed 2/15/87                                                 1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  71.  
  72.  
  73.  
  74.           matches that character.
  75.  
  76.      4.   A nonempty string s bracketed [s] (or [^s]) matches any
  77.           character in (or not in) s. In s, \ has no special
  78.           meaning, and ] may only appear as the first letter.  A
  79.           substring a-b, with a and b in ascending ASCII order,
  80.           stands for the inclusive range of ASCII characters.
  81.  
  82.      5.   A regular expression of form 1-4 followed by * matches
  83.           a sequence of 0 or more matches of the regular expres-
  84.           sion.
  85.  
  86.      6.   A regular expression, x, of form 1-8, bracketed \(x\)
  87.           matches what x matches.
  88.  
  89.      7.   A \ followed by a digit n matches a copy of the string
  90.           that the bracketed regular expression beginning with
  91.           the nth \( matched.
  92.  
  93.      8.   A regular expression of form 1-8, x, followed by a reg-
  94.           ular expression of form 1-7, y matches a match for x
  95.           followed by a match for y, with the x match being as
  96.           long as possible while still permitting a y match.
  97.  
  98.      9.   A regular expression of form 1-8 preceded by ^ (or fol-
  99.           lowed by $), is constrained to matches that begin at
  100.           the left (or end at the right) end of a line.
  101.  
  102.      10.  A regular expression of form 1-9 picks out the longest
  103.           among the leftmost matches in a line.
  104.  
  105.      11.  An empty regular expression stands for a copy of the
  106.           last regular expression encountered.
  107.  
  108.      Regular expressions are used in addresses to specify lines
  109.      and in one command (see s below) to specify a portion of a
  110.      line which is to be replaced.  If it is desired to use one
  111.      of the regular expression metacharacters as an ordinary
  112.      character, that character may be preceded by `\'.  This also
  113.      applies to the character bounding the regular expression
  114.      (often `/') and to `\' itself.
  115.  
  116.      To understand addressing in ed it is necessary to know that
  117.      at any time there is a current line. Generally speaking, the
  118.      current line is the last line affected by a command; how-
  119.      ever, the exact effect on the current line is discussed
  120.      under the description of the command.  Addresses are con-
  121.      structed as follows.
  122.  
  123.      1.   The character `.' addresses the current line.
  124.  
  125.      2.   The character `$' addresses the last line of the
  126.  
  127.  
  128.  
  129. Printed 2/15/87                                                 2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  137.  
  138.  
  139.  
  140.           buffer.
  141.  
  142.      3.   A decimal number n addresses the n-th line of the
  143.           buffer.
  144.  
  145.      4.   `'x' addresses the line marked with the name x, which
  146.           must be a lower-case letter.  Lines are marked with the
  147.           k command described below.
  148.  
  149.      5.   A regular expression enclosed in slashes `/' addresses
  150.           the line found by searching forward from the current
  151.           line and stopping at the first line containing a string
  152.           that matches the regular expression.  If necessary the
  153.           search wraps around to the beginning of the buffer.
  154.  
  155.      6.   A regular expression enclosed in queries `?' addresses
  156.           the line found by searching backward from the current
  157.           line and stopping at the first line containing a string
  158.           that matches the regular expression.  If necessary the
  159.           search wraps around to the end of the buffer.
  160.  
  161.      7.   An address followed by a plus sign `+' or a minus sign
  162.           `-' followed by a decimal number specifies that address
  163.           plus (resp. minus) the indicated number of lines.  The
  164.           plus sign may be omitted.
  165.  
  166.      8.   If an address begins with `+' or `-' the addition or
  167.           subtraction is taken with respect to the current line;
  168.           e.g. `-5' is understood to mean `.-5'.
  169.  
  170.      9.   If an address ends with `+' or `-', then 1 is added
  171.           (resp. subtracted).  As a consequence of this rule and
  172.           rule 8, the address `-' refers to the line before the
  173.           current line.  Moreover, trailing `+' and `-' charac-
  174.           ters have cumulative effect, so `--' refers to the
  175.           current line less 2.
  176.  
  177.      10.  To maintain compatibility with earlier versions of the
  178.           editor, the character `^' in addresses is equivalent to
  179.           `-'.
  180.  
  181.      Commands may require zero, one, or two addresses.  Commands
  182.      which require no addresses regard the presence of an address
  183.      as an error.  Commands which accept one or two addresses
  184.      assume default addresses when insufficient are given.  If
  185.      more addresses are given than such a command requires, the
  186.      last one or two (depending on what is accepted) are used.
  187.  
  188.      Addresses are separated from each other typically by a comma
  189.      `,'.  They may also be separated by a semicolon `;'.  In
  190.      this case the current line `.' is set to the previous
  191.      address before the next address is interpreted.  This
  192.  
  193.  
  194.  
  195. Printed 2/15/87                                                 3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  203.  
  204.  
  205.  
  206.      feature can be used to determine the starting line for for-
  207.      ward and backward searches (`/', `?').  The second address
  208.      of any two-address sequence must correspond to a line fol-
  209.      lowing the line corresponding to the first address.  The
  210.      special form `%' is an abbreviation for the address pair
  211.      `1,$'.
  212.  
  213.      In the following list of ed commands, the default addresses
  214.      are shown in parentheses.  The parentheses are not part of
  215.      the address, but are used to show that the given addresses
  216.      are the default.
  217.  
  218.      As mentioned, it is generally illegal for more than one com-
  219.      mand to appear on a line.  However, most commands may be
  220.      suffixed by `p' or by `l', in which case the current line is
  221.      either printed or listed respectively in the way discussed
  222.      below.  Commands may also be suffixed by `n', meaning the
  223.      output of the command is to be line numbered.  These suf-
  224.      fixes may be combined in any order.
  225.  
  226.      (.)a
  227.      <text>
  228.      .
  229.           The append command reads the given text and appends it
  230.           after the addressed line.  `.' is left on the last line
  231.           input, if there were any, otherwise at the addressed
  232.           line.  Address `0' is legal for this command; text is
  233.           placed at the beginning of the buffer.
  234.  
  235.      (., .)c
  236.      <text>
  237.      .
  238.           The change command deletes the addressed lines, then
  239.           accepts input text which replaces these lines.  `.' is
  240.           left at the last line input; if there were none, it is
  241.           left at the line preceding the deleted lines.
  242.  
  243.      (., .)d
  244.           The delete command deletes the addressed lines from the
  245.           buffer.  The line originally after the last line
  246.           deleted becomes the current line; if the lines deleted
  247.           were originally at the end, the new last line becomes
  248.           the current line.
  249.  
  250.      e filename
  251.           The edit command causes the entire contents of the
  252.           buffer to be deleted, and then the named file to be
  253.           read in.  `.' is set to the last line of the buffer.
  254.           The number of characters read is typed.  `filename' is
  255.           remembered for possible use as a default file name in a
  256.           subsequent r or w command.  If `filename' is missing,
  257.           the remembered name is used.
  258.  
  259.  
  260.  
  261. Printed 2/15/87                                                 4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  269.  
  270.  
  271.  
  272.      E filename
  273.           This command is the same as e, except that no diagnos-
  274.           tic results when no w has been given since the last
  275.           buffer alteration.
  276.  
  277.      f filename
  278.           The filename command prints the currently remembered
  279.           file name.  If `filename' is given, the currently
  280.           remembered file name is changed to `filename'.
  281.  
  282.      (1,$)g/regular expression/command list
  283.           In the global command, the first step is to mark every
  284.           line which matches the given regular expression.  Then
  285.           for every such line, the given command list is executed
  286.           with `.' initially set to that line.  A single command
  287.           or the first of multiple commands appears on the same
  288.           line with the global command.  All lines of a multi-
  289.           line list except the last line must be ended with `\'.
  290.           A, i, and c commands and associated input are permit-
  291.           ted; the `.' terminating input mode may be omitted if
  292.           it would be on the last line of the command list.  The
  293.           commands g and v are not permitted in the command list.
  294.  
  295.      (.)i
  296.  
  297.      <text>
  298.      .
  299.           This command inserts the given text before the
  300.           addressed line.  `.' is left at the last line input,
  301.           or, if there were none, at the line before the
  302.           addressed line.  This command differs from the a com-
  303.           mand only in the placement of the text.
  304.  
  305.      (., .+1)j
  306.           This command joins the addressed lines into a single
  307.           line; intermediate newlines simply disappear.  `.' is
  308.           left at the resulting line.
  309.  
  310.      ( . )kx
  311.           The mark command marks the addressed line with name x,
  312.           which must be a lower-case letter.  The address form
  313.           `'x' then addresses this line.
  314.  
  315.      (., .)l
  316.           The list command prints the addressed lines in an unam-
  317.           biguous way: non-graphic characters are printed in
  318.           two-digit octal, and long lines are folded.  The l com-
  319.           mand may be placed on the same line after any non-i/o
  320.           command.
  321.  
  322.      (., .)ma
  323.           The move command repositions the addressed lines after
  324.  
  325.  
  326.  
  327. Printed 2/15/87                                                 5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  335.  
  336.  
  337.  
  338.           the line addressed by a.  The last of the moved lines
  339.           becomes the current line.
  340.  
  341.      (., .)n
  342.           The number command prints the addressed lines with line
  343.           numbers and a tab at the left.
  344.  
  345.      (., .)p
  346.           The print command prints the addressed lines.  `.' is
  347.           left at the last line printed.  The p command may be
  348.           placed on the same line after any non-i/o command.
  349.  
  350.      (., .)P
  351.           This command is a synonym for p.
  352.  
  353.      q    The quit command causes ed to exit.  No automatic write
  354.           of a file is done.
  355.  
  356.      Q    This command is the same as q, except that no diagnos-
  357.           tic results when no w has been given since the last
  358.           buffer alteration.
  359.  
  360.      ($)r filename
  361.           The read command reads in the given file after the
  362.           addressed line.  If no file name is given, the remem-
  363.           bered file name, if any, is used (see e and f com-
  364.           mands).  The file name is remembered if there was no
  365.           remembered file name already.  Address `0' is legal for
  366.           r and causes the file to be read at the beginning of
  367.           the buffer.  If the read is successful, the number of
  368.           characters read is typed.  `.' is left at the last line
  369.           read in from the file.
  370.  
  371.      ( ., .)s/regular expression/replacement/       or,
  372.      ( ., .)s/regular expression/replacement/g
  373.           The substitute command searches each addressed line for
  374.           an occurrence of the specified regular expression.  On
  375.           each line in which a match is found, all matched
  376.           strings are replaced by the replacement specified, if
  377.           the global replacement indicator `g' appears after the
  378.           command.  If the global indicator does not appear, only
  379.           the first occurrence of the matched string is replaced.
  380.           It is an error for the substitution to fail on all
  381.           addressed lines.  Any punctuation character may be used
  382.           instead of `/' to delimit the regular expression and
  383.           the replacement.  `.' is left at the last line substi-
  384.           tuted.
  385.  
  386.           An ampersand `&' appearing in the replacement is
  387.           replaced by the string matching the regular expression.
  388.           The special meaning of `&' in this context may be
  389.           suppressed by preceding it by `\'.  The characters `\n'
  390.  
  391.  
  392.  
  393. Printed 2/15/87                                                 6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  401.  
  402.  
  403.  
  404.           where n is a digit, are replaced by the text matched by
  405.           the n-th regular subexpression enclosed between `\('
  406.           and `\)'.  When nested, parenthesized subexpressions
  407.           are present, n is determined by counting occurrences of
  408.           `\(' starting from the left.
  409.  
  410.           Lines may be split by substituting new-line characters
  411.           into them.  The new-line in the replacement string must
  412.           be escaped by preceding it by `\'.
  413.  
  414.           One or two trailing delimiters may be omitted, implying
  415.           the `p' suffix.  The special form `s' followed by no
  416.           delimiters repeats the most recent substitute command
  417.           on the addressed lines.  The `s' may be followed by the
  418.           letters r (use the most recent regular expression for
  419.           the left hand side, instead of the most recent left
  420.           hand side of a substitute command), p (complement the
  421.           setting of the p suffix from the previous substitu-
  422.           tion), or g (complement the setting of the g suffix).
  423.           These letters may be combined in any order.
  424.  
  425.      (., .)ta
  426.           This command acts just like the m command, except that
  427.           a copy of the addressed lines is placed after address a
  428.           (which may be 0).  `.' is left on the last line of the
  429.           copy.
  430.  
  431.      (., .)u
  432.           The undo command restores the buffer to it's state
  433.           before the most recent buffer modifying command.  The
  434.           current line is also restored.  Buffer modifying com-
  435.           mands are a, c, d, g, i, k, and v. For purposes of
  436.           undo, g and v are considered to be a single buffer
  437.           modifying command.  Undo is its own inverse.
  438.  
  439.           When ed runs out of memory (at about 8000 lines on any
  440.           16 bit mini-computer such as the PDP-11) This full undo
  441.           is not possible, and u can only undo the effect of the
  442.           most recent substitute on the current line.  This res-
  443.           tricted undo also applies to editor scripts when ed is
  444.           invoked with the - option.
  445.  
  446.      (1, $)v/regular expression/command list
  447.           This command is the same as the global command g except
  448.           that the command list is executed g with `.' initially
  449.           set to every line except those matching the regular
  450.           expression.
  451.  
  452.      (1, $)w filename
  453.           The write command writes the addressed lines onto the
  454.           given file.  If the file does not exist, it is created.
  455.           The file name is remembered if there was no remembered
  456.  
  457.  
  458.  
  459. Printed 2/15/87                                                 7
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  467.  
  468.  
  469.  
  470.           file name already.  If no file name is given, the
  471.           remembered file name, if any, is used (see e and f com-
  472.           mands).  `.' is unchanged.  If the command is success-
  473.           ful, the number of characters written is printed.
  474.  
  475.      (1, $)W filename
  476.           This command is the same as w, except that the
  477.           addressed lines are appended to the file.
  478.  
  479.      (1, $)wq filename
  480.           This command is the same as w except that afterwards a
  481.           q command is done, exiting the editor after the file is
  482.           written.
  483.  
  484.      x    A key string is demanded from the standard input.
  485.           Later r, e and w commands will encrypt and decrypt the
  486.           text with this key by the algorithm of crypt(1).  An
  487.           explicitly empty key turns off encryption.
  488.           (.+1)z    or,
  489.      (.+1)zn
  490.           This command scrolls through the buffer starting at the
  491.           addressed line.  22 (or n, if given) lines are printed.
  492.           The last line printed becomes the current line.  The
  493.           value n is sticky, in that it becomes the default for
  494.           future z commands.
  495.  
  496.      ($)= The line number of the addressed line is typed.  `.' is
  497.           unchanged by this command.
  498.  
  499.      !<shell command>
  500.           The remainder of the line after the `!' is sent to
  501.           sh(1) to be interpreted as a command.  `.' is
  502.           unchanged.
  503.  
  504.      (.+1,.+1)<newline>
  505.           An address alone on a line causes the addressed line to
  506.           be printed.  A blank line alone is equivalent to
  507.           `.+1p'; it is useful for stepping through text.  If two
  508.           addresses are present with no intervening semicolon, ed
  509.           prints the range of lines.  If they are separated by a
  510.           semicolon, the second line is printed.
  511.  
  512.      If an interrupt signal (ASCII DEL) is sent, ed prints
  513.      `?interrupted' and returns to its command level.
  514.  
  515.      Some size limitations: 512 characters per line, 256 charac-
  516.      ters per global command list, 64 characters per file name,
  517.      and, on mini computers, 128K characters in the temporary
  518.      file.  The limit on the number of lines depends on the
  519.      amount of core: each line takes 2 words.
  520.  
  521.  
  522.  
  523.  
  524.  
  525. Printed 2/15/87                                                 8
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. ED(1-ucb)         Pyramid OSx Operating System          ED(1-ucb)
  533.  
  534.  
  535.  
  536.      When reading a file, ed discards ASCII NUL characters and
  537.      all characters after the last newline.  It refuses to read
  538.      files containing non-ASCII characters.
  539.  
  540. FILES
  541.      /tmp/e*
  542.      edhup: work is saved here if terminal hangs up
  543.  
  544. SEE ALSO
  545.      B. W. Kernighan, A Tutorial Introduction to the ED Text Edi-
  546.      tor
  547.      B. W. Kernighan, Advanced editing on UNIX
  548.      ex(1), sed(1), crypt(1)
  549.  
  550. DIAGNOSTICS
  551.      `?name' for inaccessible file; `?self-explanatory message'
  552.      for other errors.
  553.  
  554.      To protect against throwing away valuable work, a q or e
  555.      command is considered to be in error, unless a w has
  556.      occurred since the last buffer change.  A second q or e will
  557.      be obeyed regardless.
  558.  
  559. BUGS
  560.      The l command mishandles DEL.
  561.      The undo command causes marks to be lost on affected lines.
  562.      The x command, -x option, and special treatment of hangups
  563.      only work on UNIX.
  564.  
  565.      The -x option is not supported outside the United States.
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591. Printed 2/15/87                                                 9
  592.  
  593.  
  594.  
  595.