home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / gnu / info / ed.info (.txt) < prev    next >
GNU Info File  |  1994-11-17  |  24KB  |  458 lines

  1. This is Info file ed.info, produced by Makeinfo-1.55 from the input
  2. file ed.texinfo.
  3.    This file documents the `ed' command, which has the purpose of
  4. editing text files.
  5.    Copyright (C) 1993 by the Free Software Foundation, Inc.
  6.    Permission is granted to make and distribute verbatim copies of this
  7. manual provided the copyright notice and this permission notice are
  8. preserved on all copies.
  9.    Permission is granted to copy and distribute modified versions of
  10. this manual under the conditions for verbatim copying, provided that
  11. the entire resulting derived work is distributed under the terms of a
  12. permission notice identical to this one.
  13.    Permission is granted to copy and distribute translations of this
  14. manual into another language, under the above conditions for modified
  15. versions, except that this permission notice may be stated in a
  16. translation approved by the Foundation.
  17. File: ed.info,  Node: Top,  Next: Description,  Prev: (dir),  Up: (dir)
  18.    This file documents the `ed' command, as of release 0.1.  You may
  19. find in this document:
  20. * Menu:
  21. * Description::                 Description
  22. * Invoking::                    Invoking GNU `ed'
  23. * Line addressing::             Line addressing
  24. * Regular expressions::         Regular expressions
  25. * Commands::                    Commands
  26. * Limitations::                 Limitations
  27. * Diagnostics::                 Diagnostics
  28. File: ed.info,  Node: Description,  Next: Invoking,  Prev: Top,  Up: Top
  29. Description
  30. ***********
  31.    `ed' is a line-oriented text editor.  It is used to create, display,
  32. modify and otherwise manipulate text files.  `red' is a restricted
  33. `ed': it can only edit files in the current directory and cannot
  34. execute shell commands.
  35.    Related programs or routines are `vi (1)', `sed (1)', `regex (3)',
  36. `bdes (1)' and `sh (1)'.  Related documents are `USD:12-13' and:
  37.      B. W. Kernighan and P. J. Plauger: "Software Tools in Pascal",
  38.      Addison-Wesley, 1981.
  39.    If invoked with a FILE argument, then a copy of FILE is read into
  40. the editor's buffer.  Changes are made to this copy and not directly to
  41. FILE itself.  Upon quitting `ed', any changes not explicitly saved with
  42. a `w' command are lost.
  43.    Editing is done in two distinct modes: "command" and "input".  When
  44. first invoked, `ed' is in command mode.  In this mode commands are read
  45. from the standard input and executed to manipulate the contents of the
  46. editor buffer.  A typical command might look like:
  47.      ,s/OLD/NEW/g
  48. which replaces all occurences of the string OLD with NEW.
  49.    When an input command, such as `a' (append), `i' (insert) or `c'
  50. (change), is given, `ed' enters input mode.  This is the primary means
  51. of adding text to a file.  In this mode, no commands are available;
  52. instead, the standard input is written directly to the editor buffer.
  53. The text up to and including a newline character defines a single line.
  54. Input mode is terminated by entering a single period (`.') on a line.
  55.    All `ed' commands operate on whole lines or ranges of lines; e.g.,
  56. the `d' command deletes lines; the `m' command moves lines, and so on.
  57. It is possible to modify only a portion of a line by means of
  58. replacement, as in the example above.  However even here, the `s'
  59. command is applied to whole lines at a time.
  60.    In general, `ed' commands consist of zero or more line addresses,
  61. followed by a single character command and possibly additional
  62. parameters; i.e., commands have the structure:
  63.      [ADDRESS [,ADDRESS]]COMMAND[PARAMETERS]
  64.    The ADDRESS(es) indicate the line or range of lines to be affected
  65. by the command.  If fewer addresses are given than the command accepts,
  66. then default addresses are supplied.
  67. File: ed.info,  Node: Invoking,  Next: Line addressing,  Prev: Description,  Up: Top
  68. Invoking GNU `ed'
  69. *****************
  70.      ed [-] [-Gs] [-p STRING] [FILE]
  71.      red [-] [-Gs] [-p STRING] [FILE]
  72.      Forces backwards compatibility.  This affects the behavior of the
  73.      `ed' commands `G', `f', `l', `m', `t' and `!!'.  If the default
  74.      behavior of these commands does not seem familiar, then try
  75.      invoking `ed' with this switch.
  76.      Suppresses diagnostics. This should be used if `ed''s standard
  77.      input is from a script.
  78. `-p STRING'
  79.      Specifies a command prompt.  This may be toggled on and off with
  80.      the `P' command.
  81.    FILE specifies the name of a file to read.  If FILE is prefixed with
  82. a bang (!), then it is interpreted as a shell command.  In this case,
  83. what is read is the standard output of FILE executed via `sh (1)'.  To
  84. read a file whose name begins with a bang, prefix the name with a
  85. backslash (`\').  The default filename is set to FILE only if it is not
  86. prefixed with a bang.
  87. File: ed.info,  Node: Line addressing,  Next: Regular expressions,  Prev: Invoking,  Up: Top
  88. Line addressing
  89. ***************
  90.    An address represents the number of a line in the buffer.  `ed'
  91. maintains a "current address" which is typically supplied to commands
  92. as the default address when none is specified.  When a file is first
  93. read, the current address is set to the last line of the file.  In
  94. general, the current address is set to the last line affected by a
  95. command.
  96.    A line address is constructed from one of the bases in the list
  97. below, optionally followed by a numeric offset.  The offset may include
  98. any combination of digits, operators (i.e., `+', `-' and `^') and
  99. whitespace.  Addresses are read from left to right, and their values
  100. are computed relative to the current address.
  101.    One exception to the rule that addresses represent line numbers is
  102. the address `0' (zero).  This means "before the first line," and is
  103. legal wherever it makes sense.
  104.    An address range is two addresses separated either by a comma or
  105. semi-colon. The value of the first address in a range cannot exceed the
  106. value of the the second.  If only one address is given in a range, then
  107. the second address is set to the given address.  If an N-tuple of
  108. addresses is given where N > 2, then the corresponding range is
  109. determined by the last two addresses in the N-tuple.  If only one
  110. address is expected, then the last address is used.
  111.    Each address in a comma-delimited range is interpreted relative to
  112. the current address.  In a semi-colon-delimited range, the first
  113. address is used to set the current address, and the second address is
  114. interpreted relative to the first.
  115.    The following address symbols are recognized.
  116.      The current line (address) in the buffer.
  117.      The last line in the buffer.
  118.      The Nth, line in the buffer where N is a number in the range `0,$'.
  119.      The previous line.  This is equivalent to `-1' and may be repeated
  120.      with cumulative effect.
  121.      The Nth previous line, where N is a non-negative number.
  122.      The next line.  This is equivalent to `+1' and may be repeated with
  123.      cumulative effect.
  124. `WHITESPACE N'
  125.      The Nth next line, where N is a non-negative number.  Whitespace
  126.      followed by a number N is interpreted as `+N'.
  127.      The first through last lines in the buffer.  This is equivalent to
  128.      the address range `1,$'.
  129.      The current through last lines in the buffer.  This is equivalent
  130.      to the address range `.,$'.
  131. `/RE/'
  132.      The next line containing the regular expression RE.  The search
  133.      wraps to the beginning of the buffer and continues down to the
  134.      current line, if necessary.  `//' repeats the last search.
  135. `?RE?'
  136.      The previous line containing the regular expression RE.  The
  137.      search wraps to the end of the buffer and continues up to the
  138.      current line, if necessary.  `??' repeats the last search.
  139. `'LC'
  140.      The line previously marked by a `k' (mark) command, where LC is a
  141.      lower case letter.
  142. File: ed.info,  Node: Regular expressions,  Next: Commands,  Prev: Line addressing,  Up: Top
  143. Regular expressions
  144. *******************
  145.    Regular expressions are patterns used in selecting text.  For
  146. example, the `ed' command
  147.      g/STRING/
  148. prints all lines containing STRING.  Regular expressions are also used
  149. by the `s' command for selecting old text to be replaced with new.
  150.    In addition to a specifying string literals, regular expressions can
  151. represent classes of strings.  Strings thus represented are said to be
  152. matched by the corresponding regular expression.  If it is possible for
  153. a regular expression to match several strings in a line, then the
  154. left-most longest match is the one selected.
  155.    The following symbols are used in constructing regular expressions:
  156.      Any character C not listed below, including `{', `}', `(', `)',
  157.      `<' and `>', matches itself.
  158.      Any backslash-escaped character C, except for `{', ``}', `(', `)',
  159.      `<' and `>', matches itself.
  160.      Matches any single character.
  161. `[CHAR-CLASS]'
  162.      Matches any single character in CHAR-CLASS.  To include a `]' in
  163.      CHAR-CLASS, it must be the first character.  A range of characters
  164.      may be specified by separating the end characters of the range
  165.      with a `-', e.g., `a-z' specifies the lower case characters.  The
  166.      following literal expressions can also be used in CHAR-CLASS to
  167.      specify sets of characters:
  168.           [:alnum:] [:cntrl:] [:lower:] [:space:]
  169.           [:alpha:] [:digit:] [:print:] [:upper:]
  170.           [:blank:] [:graph:] [:punct:] [:xdigit:]
  171.      If `-' appears as the first or last character of CHAR-CLASS, then
  172.      it matches itself.  All other characters in CHAR-CLASS match
  173.      themselves.
  174.      Patterns in CHAR-CLASS of the form:
  175.           [.COL-ELM.]
  176.           [=COL-ELM=]
  177.      where COL-ELM is a "collating element" are interpreted according
  178.      to `locale (5)' (not currently supported).  See `regex (3)' for an
  179.      explanation of these constructs.
  180. `[^CHAR-CLASS]'
  181.      Matches any single character, other than newline, not in
  182.      CHAR-CLASS.  CHAR-CLASS is defined as above.
  183.      If `^' is the first character of a regular expression, then it
  184.      anchors the regular expression to the beginning of a line.
  185.      Otherwise, it matches itself.
  186.      If `$' is the last character of a regular expression, it anchors
  187.      the regular expression to the end of a line.  Otherwise, it matches
  188.      itself.
  189.      Anchors the single character regular expression or subexpression
  190.      immediately following it to the beginning of a word.  (This may
  191.      not be available)
  192.      Anchors the single character regular expression or subexpression
  193.      immediately following it to the end of a word.  (This may not be
  194.      available)
  195. `\(RE\)'
  196.      Defines a subexpression RE.  Subexpressions may be nested.  A
  197.      subsequent backreference of the form `\N', where N is a number in
  198.      the range [1,9], expands to the text matched by the Nth
  199.      subexpression.  For example, the regular expression `\([ab]\)\1'
  200.      matches the strings `aa' and `bb' (and only these).
  201.      Subexpressions are ordered relative to their left delimiter.
  202.      Matches the single character regular expression or subexpression
  203.      immediately preceding it zero or more times.  If `*' is the first
  204.      character of a regular expression or subexpression, then it matches
  205.      itself.  The `*' operator sometimes yields unexpected results.  For
  206.      example, the regular expression `b*' matches the beginning of the
  207.      string `abbb' (as opposed to the substring `bbb'), since a null
  208.      match is the only left-most match.
  209. `{N,M}'
  210. `{N,}'
  211. `{N}'
  212.      Matches the single character regular expression or subexpression
  213.      immediately preceding it at least N and at most M times.  If M is
  214.      omitted, then it matches at least N times.  If the comma is also
  215.      omitted, then it matches exactly N times.
  216.    Additional regular expression operators may be defined depending on
  217. the particular `regex (3)' implementation.
  218. File: ed.info,  Node: Commands,  Next: Limitations,  Prev: Regular expressions,  Up: Top
  219. Commands
  220. ********
  221.    All `ed' commands are single characters, though some require
  222. additonal parameters.  If a command's parameters extend over several
  223. lines, then each line except for the last must be terminated with a
  224. backslash (`\').
  225.    In general, at most one command is allowed per line.  However, most
  226. commands accept a print suffix, which is any of `p' (print), `l'
  227. (list), or `n' (enumerate), to print the last line affected by the
  228. command.
  229.    An interrupt (typically ^C) has the effect of aborting the current
  230. command and returning the editor to command mode.
  231.    `ed' recognizes the following commands.  The commands are shown
  232. together with the default address or address range supplied if none is
  233. specified (in parenthesis).
  234. `(.)a'
  235.      Appends text to the buffer after the addressed line.  Text is
  236.      entered in input mode.  The current address is set to last line
  237.      entered.
  238. `(.,.)c'
  239.      Changes lines in the buffer.  The addressed lines are deleted from
  240.      the buffer, and text is appended in their place.  Text is entered
  241.      in input mode.  The current address is set to last line entered.
  242. `(.,.)d'
  243.      Deletes the addressed lines from the buffer.  If there is a line
  244.      after the deleted range, then the current address is set to this
  245.      line.  Otherwise the current address is set to the line before the
  246.      deleted range.
  247. `e FILE'
  248.      Edits FILE, and sets the default filename.  If FILE is not
  249.      specified, then the default filename is used.  Any lines in the
  250.      buffer are deleted before the new file is read.  The current
  251.      address is set to the last line read.
  252. `e !COMMAND'
  253.      Edits the standard output of `!COMMAND', (see `!' command below).
  254.      The default filename is unchanged.  Any lines in the buffer are
  255.      deleted before the output of COMMAND is read.  The current address
  256.      is set to the last line read.
  257. `E FILE'
  258.      Edits FILE unconditionally.  This is similar to the `e' command,
  259.      except that unwritten changes are discarded without warning.  The
  260.      current address is set to the last line read.
  261. `f FILE'
  262.      Sets the default filename to FILE.  If FILE is not specified, then
  263.      the default unescaped filename is printed.
  264. `(1,$)g /RE/COMMAND-LIST'
  265.      Applies COMMAND-LIST to each of the addressed lines matching a
  266.      regular expression RE.  The current address is set to the line
  267.      currently matched before COMMAND-LIST is executed.  At the end of
  268.      the `g' command, the current address is set to the last line
  269.      affected by COMMAND-LIST.
  270.      Each command in COMMAND-LIST must be on a separate line, and every
  271.      line except for the last must be terminated by a backslash (`\').
  272.      Any commands are allowed, except for `g', `G', `v', and `V'.  A
  273.      newline alone in COMMAND-LIST is equivalent to a `p' command.
  274. `(1,$)G /RE/'
  275.      Interactively edits the addressed lines matching a regular
  276.      expression RE.  For each matching line, the line is printed, the
  277.      current address is set, and the user is prompted to enter a
  278.      COMMAND-LIST.  At the end of the `G' command, the current address
  279.      is set to the last line affected by (the last) COMMAND-LIST.
  280.      The format of COMMAND-LIST is the same as that of the `g' command.
  281.      A newline alone acts as a null command list.  A single `&'
  282.      repeats the last non-null command list.
  283.      Toggles the printing of error explanations.  By default,
  284.      explanations are not printed.  It is recommended that ed scripts
  285.      begin with this command to aid in debugging.
  286.      Prints an explanation of the last error.
  287. `(.)i'
  288.      Inserts text in the buffer before the current line.  Text is
  289.      entered in input mode.  The current address is set to the last
  290.      line entered.
  291. `(.,.+1)j'
  292.      Joins the addressed lines.  The addressed lines are deleted from
  293.      the buffer and replaced by a single line containing their joined
  294.      text.  The current address is set to the resultant line.
  295. `(.)k LC'
  296.      Marks a line with a lower case letter LC.  The line can then be
  297.      addressed as `'LC' (i.e., a single quote followed by LC) in
  298.      subsequent commands.  The mark is not cleared until the line is
  299.      deleted or otherwise modified.
  300. `(.,.)l'
  301.      Prints the addressed lines unambiguously.  If a single line fills
  302.      for than one screen (as might be the case when viewing a binary
  303.      file, for instance), a `--More--' prompt is printed on the last
  304.      line.  `ed' waits until the RETURN key is pressed before displaying
  305.      the next screen.  The current address is set to the last line
  306.      printed.
  307. `(.,.)m(.)'
  308.      Moves lines in the buffer.  The addressed lines are moved to after
  309.      the right-hand destination address, which may be the address `0'
  310.      (zero).  The current address is set to the last line moved.
  311. `(.,.)n'
  312.      Prints the addressed lines along with their line numbers.  The
  313.      current address is set to the last line printed.
  314. `(.,.)p'
  315.      Prints the addressed lines. The current address is set to the last
  316.      line printed.
  317.      Toggles the command prompt on and off.  Unless a prompt was
  318.      specified by with command-line option `-p STRING', the command
  319.      prompt is by default turned off.
  320.      Quits `ed'.
  321.      Quits `ed' unconditionally.  This is similar to the `q' command,
  322.      except that unwritten changes are discarded without warning.
  323. `($)r FILE'
  324.      Reads FILE to after the addressed line.  If FILE is not specified,
  325.      then the default filename is used.  If there was no default
  326.      filename prior to the command, then the default filename is set to
  327.      FILE.  Otherwise, the default filename is unchanged.  The current
  328.      address is set to the last line read.
  329. `($)r !COMMAND'
  330.      Reads to after the addressed line the standard output of
  331.      `!command', (see the `!' command below).  The default filename is
  332.      unchanged.  The current address is set to the last line read.
  333. `(.,.)s /RE/REPLACEMENT/'
  334. `(.,.)s /RE/REPLACEMENT/g'
  335. `(.,.)s /RE/REPLACEMENT/n'
  336.      Replaces text in the addressed lines matching a regular expression
  337.      RE with REPLACEMENT.  By default, only the first match in each
  338.      line is replaced.  If the `g' (global) suffix is given, then every
  339.      match to be replaced.  The `n' suffix, where N is a postive
  340.      number, causes only the Nth match to be replaced.  It is an error
  341.      if no substitutions are performed on any of the addressed lines.
  342.      The current address is set the last line affected.
  343.      RE and REPLACEMENT may be delimited by any character other than
  344.      space and newline (see the `s' command below).  If one or two of
  345.      the last delimiters is omitted, then the last line affected is
  346.      printed as though the print suffix `p' were specified.
  347.      An unescaped `&' in REPLACEMENT is replaced by the currently
  348.      matched text.  The character sequence `\M' where M is a number in
  349.      the range [1,9], is replaced by the Mth backreference expression
  350.      of the matched text.  If REPLACEMENT consists of a single `%',
  351.      then REPLACEMENT from the last substitution is used.  Newlines may
  352.      be embedded in REPLACEMENT if they are escaped with a backslash
  353.      (`\').
  354. `(.,.)s'
  355.      Repeats the last substitution.  This form of the `s' command
  356.      accepts a count suffix N, or any combination of the characters
  357.      `r', `g', and `p'.  If a count suffix N is given, then only the
  358.      Nth match is replaced.  The `r' suffix causes the regular
  359.      expression of the last search to be used instead of the that of
  360.      the last substitution.  The `g' suffix toggles the global suffix
  361.      of the last substitution.  The `p' suffix toggles the print suffix
  362.      of the last substitution The current address is set to the last
  363.      line affected.
  364. `(.,.)t(.)'
  365.      Copies (i.e., transfers) the addressed lines to after the
  366.      right-hand destination address, which may be the address `0'
  367.      (zero).  The current address is set to the last line copied.
  368.      Undoes the last command and restores the current address to what
  369.      it was before the command.  The global commands `g', `G', `v', and
  370.      `V' are treated as a single command by undo.  `u' is its own
  371.      inverse.
  372. `(1,$)v /PAT/COMMAND-LIST'
  373.      Applies COMMAND-LIST to each of the addressed lines not matching a
  374.      regular expression RE.  This is similar to the `g' command.
  375. `(1,$)V /RE/'
  376.      Interactively edits the addressed lines not matching a regular
  377.      expression RE.  This is similar to the `G' command.
  378. `(1,$)w FILE'
  379.      Writes the addressed lines to FILE.  Any previous contents of FILE
  380.      is lost without warning.  If there is no default filename, then
  381.      the default filename is set to FILE, otherwise it is unchanged.
  382.      If no filename is specified, then the default filename is used.
  383.      The current address is unchanged.
  384. `(1,$)wq FILE'
  385.      Writes the addressed lines to FILE, and then executes a `q'
  386.      command.
  387. `(1,$)w !COMMAND'
  388.      Writes the addressed lines to the standard input of `!COMMAND',
  389.      (see the `!' command below).  The default filename and current
  390.      address are unchanged.
  391. `(1,$)W FILE'
  392.      Appends the addressed lines to the end of FILE.  This is similar
  393.      to the `w' command, expect that the previous contents of file is
  394.      not clobbered.  The current address is unchanged.
  395. `(.+1)z N'
  396.      Scrolls N lines at a time starting at addressed line.  If N is not
  397.      specified, then the current window size is used.  The current
  398.      address is set to the last line printed.
  399. `! COMMAND'
  400.      Executes COMMAND via `sh (1)'.  If the first character of COMMAND
  401.      is `!', then it is replaced by text of the previous `!COMMAND'.
  402.      `ed' does not process COMMAND for backslash (`\') escapes.
  403.      However, an unescaped `%' is replaced by the default filename.
  404.      When the shell returns from execution, a `!' is printed to the
  405.      standard output.  The current line is unchanged.
  406. `(.,.)#'
  407.      Begins a comment;  the rest of the line, up to a newline, is
  408.      ignored.  If a line address followed by a semi-colon is given,
  409.      then the current address is set to that address.  Otherwise, the
  410.      current address is unchanged.
  411. `($)='
  412.      Prints the line number of the addressed line.
  413. `(.+1)newline'
  414.      Prints the addressed line, and sets the current address to that
  415.      line.
  416. File: ed.info,  Node: Limitations,  Next: Diagnostics,  Prev: Commands,  Up: Top
  417. Limitations
  418. ***********
  419.    The buffer files are kept in `/tmp/ed.*'.  If the terminal hangs up,
  420. `ed' attempts to write the buffer to file `ed.hup'.
  421.    `ed' processes FILE arguments for backslash escapes, i.e., in a
  422. filename, any characters preceded by a backslash (`\') are interpreted
  423. literally.
  424.    If a text (non-binary) file is not terminated by a newline character,
  425. then `ed' appends one on reading/writing it.  In the case of a binary
  426. file, `ed' does not append a newline on reading/writing.
  427.    Per line overhead: 4 `int's.
  428. File: ed.info,  Node: Diagnostics,  Prev: Limitations,  Up: Top
  429. Diagnostics
  430. ***********
  431.    When an error occurs, `ed' prints a `?' and either returns to
  432. command mode or exits if its input is from a script.  An explanation of
  433. the last error can be printed with the `h' (help) command.
  434.    Since the `g' (global) command  masks any errors from failed
  435. searches and substitutions, it can be used to perform conditional
  436. operations in scripts; e.g.,
  437.      g/OLD/s//NEW/
  438. replaces any occurrences of OLD with NEW.  If the `u' (undo) command
  439. occurs in a global command list, then the command list is executed only
  440. once.
  441.    If diagnostics are not disabled, attempting to quit `ed' or edit
  442. another file before writing a modified buffer results in an error.  If
  443. the command is entered a second time, it succeeds, but any changes to
  444. the buffer are lost.
  445. Tag Table:
  446. Node: Top
  447. Node: Description
  448. Node: Invoking
  449. Node: Line addressing
  450. Node: Regular expressions
  451. Node: Commands
  452. 11849
  453. Node: Limitations
  454. 22271
  455. Node: Diagnostics
  456. 22889
  457. End Tag Table
  458.