home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / info / ed.info < prev    next >
Encoding:
GNU Info File  |  1996-10-12  |  28.7 KB  |  770 lines

  1. This is Info file ed.info, produced by Makeinfo-1.64 from the input
  2. file ed.texinfo.
  3.  
  4.    This file documents the `ed' command, which has the purpose of
  5. editing text files.
  6.  
  7.    Copyright (C) 1993 by the Free Software Foundation, Inc.
  8.  
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.  
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided that
  15. the entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17.  
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions, except that this permission notice may be stated in a
  21. translation approved by the Foundation.
  22.  
  23. 
  24. File: ed.info,  Node: Top,  Next: Intro,  Prev: (dir),  Up: (dir)
  25.  
  26.  
  27.  
  28.    This info file documents the `ed' text editor, as of release 0.2.
  29. You may find in this document:
  30.  
  31. * Menu:
  32.  
  33. * Intro::                       An introduction to line editing with  `ed'
  34. * Invoking ed::                 GNU `ed' command-line options
  35. * Line addressing::             Specifying lines/ranges in the buffer
  36. * Regular expressions::         Patterns for selecting text
  37. * Commands::                    Commands recognized by GNU `ed'
  38. * Limitations::                 Intrinsic limits of GNU `ed'
  39. * Diagnostics::                 GNU `ed' error handling
  40.  
  41. 
  42. File: ed.info,  Node: Intro,  Next: Invoking ed,  Prev: Top,  Up: Top
  43.  
  44. Intro
  45. *****
  46.  
  47.    `ed' is a line-oriented text editor.  It is used to create, display,
  48. modify and otherwise manipulate text files, both interactively and via
  49. shell scripts.  A restricted version of `ed', `red', can only edit
  50. files in the current directory and cannot execute shell commands.  `ed'
  51. is the "standard" text editor in the sense that it is the original
  52. editor for Unix, and thus widely available.  For most purposes,
  53. however, it is superceded by full-screen editors such as Emacs and Vi.
  54.  
  55.    The sample sessions below illustrate some basic concepts of line
  56. editing with `ed'.  We begin by creating a file, `sonnet', with some
  57. help from Shakespeare.  As with the shell, all input to `ed' must be
  58. followed by a newline character.  Comments begin with a `#'.
  59.  
  60.      $ ed
  61.      # The `a' command is for appending text to the editor buffer.
  62.      a
  63.      No more be grieved at that which thou hast done.
  64.      Roses have thorns, and filvers foutians mud.
  65.      Clouds and eclipses stain both moon and sun,
  66.      And loathsome canker lives in sweetest bud.
  67.      .
  68.      # Entering a single period on a line returns `ed' to command mode.
  69.      # Now write the buffer to the file `sonnet' and quit:
  70.      w sonnet
  71.      183
  72.      # `ed' reports the number of characters written.
  73.      q
  74.      $ ls -l
  75.      total 2
  76.      -rw-rw-r--    1 alm           183 Nov 10 01:16 sonnet
  77.      $
  78.  
  79.    Editing with `ed' is done in two distinct modes: "command" and
  80. "input".  When first invoked, `ed' is in command mode.  In this mode
  81. commands are read from the standard input and executed to manipulate
  82. the contents of the editor buffer.  When an input command, such as `a'
  83. (append), `i' (insert) or `c' (change), is given, `ed' enters input
  84. mode.  This is the primary means of adding text to a file.  In this
  85. mode, no commands are available; instead, the standard input is written
  86. directly to the editor buffer. A "line" consists of the text up to and
  87. including a newline character.  Input mode is terminated by entering a
  88. single period (`.') on a line.
  89.  
  90.    In the next example, some typos are corrected in the file `sonnet'.
  91.  
  92.      $ ed sonnet
  93.      183
  94.      # Begin by printing the buffer to the terminal with the `p' command.
  95.      # The `,' means ``all lines.''
  96.      ,p
  97.      No more be grieved at that which thou hast done.
  98.      Roses have thorns, and filvers foutians mud.
  99.      Clouds and eclipses stain both moon and sun,
  100.      And loathsome canker lives in sweetest bud.
  101.      # Select line 2 for editing.
  102.      2
  103.      Roses have thorns, and filvers foutians mud.
  104.      # Use the substitute command, `s', to replace `filvers' with `silver',
  105.      # and print the result.
  106.      s/filvers/silver/p
  107.      Roses have thorns, and silver foutians mud.
  108.      # And correct the spelling of `fountains'.
  109.      s/utia/untai/p
  110.      Roses have thorns, and silver fountains mud.
  111.      w sonnet
  112.      183
  113.      q
  114.      $
  115.  
  116.    `ed' may be invoked with or without arguments *Note Invoking ed::.
  117. When invoked with a FILE argument, a copy of FILE is read into the
  118. editor's buffer.  Changes are made to this copy and not directly to
  119. FILE itself.  Upon quitting `ed', any changes not explicitly saved with
  120. a `w' command *Note Commands::, are lost.
  121.  
  122.    Since `ed' is line-oriented, we have to tell it which line, or range
  123. of lines we want to edit.  In the above example, we do this by
  124. specifying the line's number, or sequence in the buffer.  Alternatively,
  125. we could have specified a unique string in the line, e.g., `/filvers/',
  126. where the `/'s delimit the string in question.  Subsequent commands
  127. affect only the selected line, a.k.a. the "current" line.  Portions of
  128. that line are then replaced with the substitute command, whose syntax is
  129. `s/OLD/NEW/'.
  130.  
  131.    Although `ed' accepts only one command per line, the print command
  132. `p' is an exception, and may be appended to the end of most commands.
  133.  
  134.    In the next example, a title is added to our sonnet.
  135.  
  136.      $ ed sonnet
  137.      183
  138.      a
  139.       Sonnet #50
  140.      .
  141.      ,p
  142.      No more be grieved at that which thou hast done.
  143.      Roses have thorns, and silver fountains mud.
  144.      Clouds and eclipses stain both moon and sun,
  145.      And loathsome canker lives in sweetest bud.
  146.       Sonnet #50
  147.      # The title got appended to the end; we should have used `0a'
  148.      # to append ``before the first line.''
  149.      # Move the title to its proper place.
  150.      5m0p
  151.       Sonnet #50
  152.      # The title is now the first line, and the current line has been
  153.      # set to this line as well.
  154.      ,p
  155.       Sonnet #50
  156.      No more be grieved at that which thou hast done.
  157.      Roses have thorns, and silver fountains mud.
  158.      Clouds and eclipses stain both moon and sun,
  159.      And loathsome canker lives in sweetest bud.
  160.      wq sonnet
  161.      195
  162.      $
  163.  
  164.    When `ed' opens a file, the current line is initially set to the last
  165. line of that file.   Similarly, the move command `m' sets the current
  166. line to the last line moved.
  167.  
  168.    In summary: All `ed' commands operate on whole lines or ranges of
  169. lines; e.g., the `d' command deletes lines; the `m' command moves
  170. lines, and so on.  It is possible to modify only a portion of a line by
  171. means of replacement, as in the second example above.  However even
  172. there, the `s' command is applied to whole lines at a time.
  173.  
  174.    Structurally, `ed' commands consist of zero or more line addresses,
  175. followed by a single character command and possibly additional
  176. parameters; i.e., commands have the structure:
  177.  
  178.      [ADDRESS [,ADDRESS]]COMMAND[PARAMETERS]
  179.  
  180.    The ADDRESS(es) indicate the line or range of lines to be affected
  181. by the command.  If fewer addresses are given than the command accepts,
  182. then default addresses are supplied.
  183.  
  184.    Related programs or routines are `vi (1)', `sed (1)', `regex (3)',
  185. `sh (1)'.  Relevant documents are:
  186.  
  187.      Unix User's Manual Supplementary Documents: 12 -- 13
  188.  
  189.      B. W. Kernighan and P. J. Plauger: "Software Tools in Pascal",
  190.      Addison-Wesley, 1981.
  191.  
  192. 
  193. File: ed.info,  Node: Invoking ed,  Next: Line addressing,  Prev: Intro,  Up: Top
  194.  
  195. Invoking GNU `ed'
  196. *****************
  197.  
  198.      ed [-] [-Gs] [-p STRING] [FILE]
  199.      red [-] [-Gs] [-p STRING] [FILE]
  200.  
  201. `-G'
  202.      Forces backwards compatibility.  This affects the behavior of the
  203.      `ed' commands `G', `V', `f', `l', `m', `t' and `!!'.  If the
  204.      default behavior of these commands does not seem familiar, then
  205.      try invoking `ed' with this switch.
  206.  
  207. `-s'
  208. `-'
  209.      Suppresses diagnostics. This should be used if `ed''s standard
  210.      input is from a script.
  211.  
  212. `-p STRING'
  213.      Specifies a command prompt.  This may be toggled on and off with
  214.      the `P' command.
  215.  
  216.    FILE specifies the name of a file to read.  If FILE is prefixed with
  217. a bang (!), then it is interpreted as a shell command.  In this case,
  218. what is read is the standard output of FILE executed via `sh (1)'.  To
  219. read a file whose name begins with a bang, prefix the name with a
  220. backslash (`\').  The default filename is set to FILE only if it is not
  221. prefixed with a bang.
  222.  
  223. 
  224. File: ed.info,  Node: Line addressing,  Next: Regular expressions,  Prev: Invoking ed,  Up: Top
  225.  
  226. Line addressing
  227. ***************
  228.  
  229.    An address represents the number of a line in the buffer.  `ed'
  230. maintains a "current address" which is typically supplied to commands
  231. as the default address when none is specified.  When a file is first
  232. read, the current address is set to the last line of the file.  In
  233. general, the current address is set to the last line affected by a
  234. command.
  235.  
  236.    A line address is constructed from one of the bases in the list
  237. below, optionally followed by a numeric offset.  The offset may include
  238. any combination of digits, operators (i.e., `+', `-' and `^') and
  239. whitespace.  Addresses are read from left to right, and their values
  240. are computed relative to the current address.
  241.  
  242.    One exception to the rule that addresses represent line numbers is
  243. the address `0' (zero).  This means "before the first line," and is
  244. legal wherever it makes sense.
  245.  
  246.    An address range is two addresses separated either by a comma or
  247. semicolon. The value of the first address in a range cannot exceed the
  248. value of the the second.  If only one address is given in a range, then
  249. the second address is set to the given address.  If an N-tuple of
  250. addresses is given where N > 2, then the corresponding range is
  251. determined by the last two addresses in the N-tuple.  If only one
  252. address is expected, then the last address is used.
  253.  
  254.    Each address in a comma-delimited range is interpreted relative to
  255. the current address.  In a semicolon-delimited range, the first address
  256. is used to set the current address, and the second address is
  257. interpreted relative to the first.
  258.  
  259.    The following address symbols are recognized.
  260.  
  261. `.'
  262.      The current line (address) in the buffer.
  263.  
  264. `$'
  265.      The last line in the buffer.
  266.  
  267. `N'
  268.      The Nth, line in the buffer where N is a number in the range `0,$'.
  269.  
  270. `-'
  271. `^'
  272.      The previous line.  This is equivalent to `-1' and may be repeated
  273.      with cumulative effect.
  274.  
  275. `-N'
  276. `^N'
  277.      The Nth previous line, where N is a non-negative number.
  278.  
  279. `+'
  280.      The next line.  This is equivalent to `+1' and may be repeated with
  281.      cumulative effect.
  282.  
  283. `+N'
  284. `WHITESPACE N'
  285.      The Nth next line, where N is a non-negative number.  Whitespace
  286.      followed by a number N is interpreted as `+N'.
  287.  
  288. `,'
  289. `%'
  290.      The first through last lines in the buffer.  This is equivalent to
  291.      the address range `1,$'.
  292.  
  293. `;'
  294.      The current through last lines in the buffer.  This is equivalent
  295.      to the address range `.,$'.
  296.  
  297. `/RE/'
  298.      The next line containing the regular expression RE.  The search
  299.      wraps to the beginning of the buffer and continues down to the
  300.      current line, if necessary.  `//' repeats the last search.
  301.  
  302. `?RE?'
  303.      The previous line containing the regular expression RE.  The
  304.      search wraps to the end of the buffer and continues up to the
  305.      current line, if necessary.  `??' repeats the last search.
  306.  
  307. `'LC'
  308.      The line previously marked by a `k' (mark) command, where LC is a
  309.      lower case letter.
  310.  
  311. 
  312. File: ed.info,  Node: Regular expressions,  Next: Commands,  Prev: Line addressing,  Up: Top
  313.  
  314. Regular expressions
  315. *******************
  316.  
  317.    Regular expressions are patterns used in selecting text.  For
  318. example, the `ed' command
  319.  
  320.      g/STRING/
  321.  
  322. prints all lines containing STRING.  Regular expressions are also used
  323. by the `s' command for selecting old text to be replaced with new.
  324.  
  325.    In addition to a specifying string literals, regular expressions can
  326. represent classes of strings.  Strings thus represented are said to be
  327. matched by the corresponding regular expression.  If it is possible for
  328. a regular expression to match several strings in a line, then the
  329. left-most longest match is the one selected.
  330.  
  331.    The following symbols are used in constructing regular expressions:
  332.  
  333. `C'
  334.      Any character C not listed below, including `{', `}', `(', `)',
  335.      `<' and `>', matches itself.
  336.  
  337. `\C'
  338.      Any backslash-escaped character C, other than `{', ``}', `(', `)',
  339.      `<', `>', `b', `B', `w', `W', `+' and `?', matches itself.
  340.  
  341. `.'
  342.      Matches any single character.
  343.  
  344. `[CHAR-CLASS]'
  345.      Matches any single character in CHAR-CLASS.  To include a `]' in
  346.      CHAR-CLASS, it must be the first character.  A range of characters
  347.      may be specified by separating the end characters of the range
  348.      with a `-', e.g., `a-z' specifies the lower case characters.  The
  349.      following literal expressions can also be used in CHAR-CLASS to
  350.      specify sets of characters:
  351.  
  352.           [:alnum:] [:cntrl:] [:lower:] [:space:]
  353.           [:alpha:] [:digit:] [:print:] [:upper:]
  354.           [:blank:] [:graph:] [:punct:] [:xdigit:]
  355.  
  356.      If `-' appears as the first or last character of CHAR-CLASS, then
  357.      it matches itself.  All other characters in CHAR-CLASS match
  358.      themselves.
  359.  
  360.      Patterns in CHAR-CLASS of the form:
  361.           [.COL-ELM.]
  362.           [=COL-ELM=]
  363.  
  364.      where COL-ELM is a "collating element" are interpreted according
  365.      to `locale (5)' (not currently supported).  See `regex (3)' for an
  366.      explanation of these constructs.
  367.  
  368. `[^CHAR-CLASS]'
  369.      Matches any single character, other than newline, not in
  370.      CHAR-CLASS.  CHAR-CLASS is defined as above.
  371.  
  372. `^'
  373.      If `^' is the first character of a regular expression, then it
  374.      anchors the regular expression to the beginning of a line.
  375.      Otherwise, it matches itself.
  376.  
  377. `$'
  378.      If `$' is the last character of a regular expression, it anchors
  379.      the regular expression to the end of a line.  Otherwise, it matches
  380.      itself.
  381.  
  382. `\(RE\)'
  383.      Defines a (possibly null) subexpression RE.  Subexpressions may be
  384.      nested.  A subsequent backreference of the form `\N', where N is a
  385.      number in the range [1,9], expands to the text matched by the Nth
  386.      subexpression. For example, the regular expression `\(a.c\)\1'
  387.      matches the string `abcabc', but not `abcadc'.  Subexpressions are
  388.      ordered relative to their left delimiter.
  389.  
  390. `*'
  391.      Matches the single character regular expression or subexpression
  392.      immediately preceding it zero or more times.  If `*' is the first
  393.      character of a regular expression or subexpression, then it matches
  394.      itself.  The `*' operator sometimes yields unexpected results.  For
  395.      example, the regular expression `b*' matches the beginning of the
  396.      string `abbb', as opposed to the substring `bbb', since a null
  397.      match is the only left-most match.
  398.  
  399. `\{N,M\}'
  400. `\{N,\}'
  401. `\{N\}'
  402.      Matches the single character regular expression or subexpression
  403.      immediately preceding it at least N and at most M times.  If M is
  404.      omitted, then it matches at least N times.  If the comma is also
  405.      omitted, then it matches exactly N times.  If any of these forms
  406.      occurs first in a regular expression or subexpression, then it is
  407.      interpreted literally (i.e., the regular expression `\{2\}'
  408.      matches the string `{2}', and so on).
  409.  
  410. `\<'
  411. `\>'
  412.      Anchors the single character regular expression or subexpression
  413.      immediately following it to the beginning (in the case of `\<') or
  414.      ending (in the case of `\>') of a "word", i.e., in ASCII, a
  415.      maximal string of alphanumeric characters, including the
  416.      underscore (_).
  417.  
  418.    The following extended operators are preceded by a backslash `\' to
  419. distinguish them from traditional `ed' syntax.
  420.  
  421. `\`'
  422. `\''
  423.      Unconditionally matches the beginning `\`' or ending `\'' of a
  424.      line.
  425.  
  426. `\?'
  427.      Optionally matches the single character regular expression or
  428.      subexpression immediately preceding it.  For example, the regular
  429.      expression `a[bd]\?c' matches the strings `abc', `adc' and `ac'.
  430.      If `\?' occurs at the beginning of a regular expressions or
  431.      subexpression, then it matches a literal `?'.
  432.  
  433. `\+'
  434.      Matches the single character regular expression or subexpression
  435.      immediately preceding it one or more times.  So the regular
  436.      expression `a+' is shorthand for `aa*'.  If `\+' occurs at the
  437.      beginning of a regular expression or subexpression, then it
  438.      matches a literal `+'.
  439.  
  440. `\b'
  441.      Matches the beginning or ending (null string) of a word.  Thus the
  442.      regular expression `\bhello\b' is equivalent to `\<hello\>'.
  443.      However, `\b\b' is a valid regular expression whereas `\<\>' is
  444.      not.
  445.  
  446. `\B'
  447.      Matches (a null string) inside a word.
  448.  
  449. `\w'
  450.      Matches any character in a word.
  451.  
  452. `\W'
  453.      Matches any character not in a word.
  454.  
  455. 
  456. File: ed.info,  Node: Commands,  Next: Limitations,  Prev: Regular expressions,  Up: Top
  457.  
  458. Commands
  459. ********
  460.  
  461.    All `ed' commands are single characters, though some require
  462. additonal parameters.  If a command's parameters extend over several
  463. lines, then each line except for the last must be terminated with a
  464. backslash (`\').
  465.  
  466.    In general, at most one command is allowed per line.  However, most
  467. commands accept a print suffix, which is any of `p' (print), `l'
  468. (list), or `n' (enumerate), to print the last line affected by the
  469. command.
  470.  
  471.    An interrupt (typically ^C) has the effect of aborting the current
  472. command and returning the editor to command mode.
  473.  
  474.    `ed' recognizes the following commands.  The commands are shown
  475. together with the default address or address range supplied if none is
  476. specified (in parenthesis).
  477.  
  478. `(.)a'
  479.      Appends text to the buffer after the addressed line, which may be
  480.      the address `0' (zero).  Text is entered in input mode.  The
  481.      current address is set to last line entered.
  482.  
  483. `(.,.)c'
  484.      Changes lines in the buffer.  The addressed lines are deleted from
  485.      the buffer, and text is appended in their place.  Text is entered
  486.      in input mode.  The current address is set to last line entered.
  487.  
  488. `(.,.)d'
  489.      Deletes the addressed lines from the buffer.  If there is a line
  490.      after the deleted range, then the current address is set to this
  491.      line.  Otherwise the current address is set to the line before the
  492.      deleted range.
  493.  
  494. `e FILE'
  495.      Edits FILE, and sets the default filename.  If FILE is not
  496.      specified, then the default filename is used.  Any lines in the
  497.      buffer are deleted before the new file is read.  The current
  498.      address is set to the last line read.
  499.  
  500. `e !COMMAND'
  501.      Edits the standard output of `!COMMAND', (see the `!' command
  502.      below).  The default filename is unchanged.  Any lines in the
  503.      buffer are deleted before the output of COMMAND is read.  The
  504.      current address is set to the last line read.
  505.  
  506. `E FILE'
  507.      Edits FILE unconditionally.  This is similar to the `e' command,
  508.      except that unwritten changes are discarded without warning.  The
  509.      current address is set to the last line read.
  510.  
  511. `f FILE'
  512.      Sets the default filename to FILE.  If FILE is not specified, then
  513.      the default unescaped filename is printed.
  514.  
  515. `(1,$)g /RE/COMMAND-LIST'
  516.      Applies COMMAND-LIST to each of the addressed lines matching a
  517.      regular expression RE.  The current address is set to the line
  518.      currently matched before COMMAND-LIST is executed.  At the end of
  519.      the `g' command, the current address is set to the last line
  520.      affected by COMMAND-LIST.
  521.  
  522.      Each command in COMMAND-LIST must be on a separate line, and every
  523.      line except for the last must be terminated by a backslash (`\').
  524.      Any commands are allowed, except for `g', `G', `v', and `V'.  By
  525.      default, a newline alone in COMMAND-LIST is equivalent to a `p'
  526.      command.  If `ed' is invoked with the command-line option `-G',
  527.      then a newline in COMMAND-LIST is equivalent to a `.+1p' command.
  528.  
  529. `(1,$)G /RE/'
  530.      Interactively edits the addressed lines matching a regular
  531.      expression RE.  For each matching line, the line is printed, the
  532.      current address is set, and the user is prompted to enter a
  533.      COMMAND-LIST.  At the end of the `G' command, the current address
  534.      is set to the last line affected by (the last) COMMAND-LIST.
  535.  
  536.      The format of COMMAND-LIST is the same as that of the `g' command.
  537.      A newline alone acts as a null command list.  A single `&'
  538.      repeats the last non-null command list.
  539.  
  540. `H'
  541.      Toggles the printing of error explanations.  By default,
  542.      explanations are not printed.  It is recommended that ed scripts
  543.      begin with this command to aid in debugging.
  544.  
  545. `h'
  546.      Prints an explanation of the last error.
  547.  
  548. `(.)i'
  549.      Inserts text in the buffer before the current line.  Text is
  550.      entered in input mode.  The current address is set to the last
  551.      line entered.
  552.  
  553. `(.,.+1)j'
  554.      Joins the addressed lines.  The addressed lines are deleted from
  555.      the buffer and replaced by a single line containing their joined
  556.      text.  The current address is set to the resultant line.
  557.  
  558. `(.)k LC'
  559.      Marks a line with a lower case letter LC.  The line can then be
  560.      addressed as `'LC' (i.e., a single quote followed by LC) in
  561.      subsequent commands.  The mark is not cleared until the line is
  562.      deleted or otherwise modified.
  563.  
  564. `(.,.)l'
  565.      Prints the addressed lines unambiguously.  If invoked from a
  566.      terminal, `ed' pauses at the end of each page until a newline is
  567.      entered.  The current address is set to the last line printed.
  568.  
  569. `(.,.)m(.)'
  570.      Moves lines in the buffer.  The addressed lines are moved to after
  571.      the right-hand destination address, which may be the address `0'
  572.      (zero).  The current address is set to the last line moved.
  573.  
  574. `(.,.)n'
  575.      Prints the addressed lines along with their line numbers.  The
  576.      current address is set to the last line printed.
  577.  
  578. `(.,.)p'
  579.      Prints the addressed lines.  If invoked from a terminal, `ed'
  580.      pauses at the end of each page until a newline is entered.  The
  581.      current address is set to the last line printed.
  582.  
  583. `P'
  584.      Toggles the command prompt on and off.  Unless a prompt is
  585.      specified with command-line option `-p STRING', the command prompt
  586.      is by default turned off.
  587.  
  588. `q'
  589.      Quits `ed'.
  590.  
  591. `Q'
  592.      Quits `ed' unconditionally.  This is similar to the `q' command,
  593.      except that unwritten changes are discarded without warning.
  594.  
  595. `($)r FILE'
  596.      Reads FILE to after the addressed line.  If FILE is not specified,
  597.      then the default filename is used.  If there is no default
  598.      filename prior to the command, then the default filename is set to
  599.      FILE.  Otherwise, the default filename is unchanged.  The current
  600.      address is set to the last line read.
  601.  
  602. `($)r !COMMAND'
  603.      Reads to after the addressed line the standard output of
  604.      `!command', (see the `!' command below).  The default filename is
  605.      unchanged.  The current address is set to the last line read.
  606.  
  607. `(.,.)s /RE/REPLACEMENT/'
  608. `(.,.)s /RE/REPLACEMENT/g'
  609. `(.,.)s /RE/REPLACEMENT/n'
  610.      Replaces text in the addressed lines matching a regular expression
  611.      RE with REPLACEMENT.  By default, only the first match in each
  612.      line is replaced.  If the `g' (global) suffix is given, then every
  613.      match to be replaced.  The `n' suffix, where N is a postive
  614.      number, causes only the Nth match to be replaced.  It is an error
  615.      if no substitutions are performed on any of the addressed lines.
  616.      The current address is set the last line affected.
  617.  
  618.      RE and REPLACEMENT may be delimited by any character other than
  619.      space and newline (see the `s' command below).  If one or two of
  620.      the last delimiters is omitted, then the last line affected is
  621.      printed as though the print suffix `p' were specified.
  622.  
  623.      An unescaped `&' in REPLACEMENT is replaced by the currently
  624.      matched text.  The character sequence `\M' where M is a number in
  625.      the range [1,9], is replaced by the Mth backreference expression
  626.      of the matched text.  If REPLACEMENT consists of a single `%',
  627.      then REPLACEMENT from the last substitution is used.  Newlines may
  628.      be embedded in REPLACEMENT if they are escaped with a backslash
  629.      (`\').
  630.  
  631. `(.,.)s'
  632.      Repeats the last substitution.  This form of the `s' command
  633.      accepts a count suffix N, or any combination of the characters
  634.      `r', `g', and `p'.  If a count suffix N is given, then only the
  635.      Nth match is replaced.  The `r' suffix causes the regular
  636.      expression of the last search to be used instead of the that of
  637.      the last substitution.  The `g' suffix toggles the global suffix
  638.      of the last substitution.  The `p' suffix toggles the print suffix
  639.      of the last substitution The current address is set to the last
  640.      line affected.
  641.  
  642. `(.,.)t(.)'
  643.      Copies (i.e., transfers) the addressed lines to after the
  644.      right-hand destination address, which may be the address `0'
  645.      (zero).  The current address is set to the last line copied.
  646.  
  647. `u'
  648.      Undoes the last command and restores the current address to what
  649.      it was before the command.  The global commands `g', `G', `v', and
  650.      `V' are treated as a single command by undo.  `u' is its own
  651.      inverse.
  652.  
  653. `(1,$)v /RE/COMMAND-LIST'
  654.      Applies COMMAND-LIST to each of the addressed lines not matching a
  655.      regular expression RE.  This is similar to the `g' command.
  656.  
  657. `(1,$)V /RE/'
  658.      Interactively edits the addressed lines not matching a regular
  659.      expression RE.  This is similar to the `G' command.
  660.  
  661. `(1,$)w FILE'
  662.      Writes the addressed lines to FILE.  Any previous contents of FILE
  663.      is lost without warning.  If there is no default filename, then
  664.      the default filename is set to FILE, otherwise it is unchanged.
  665.      If no filename is specified, then the default filename is used.
  666.      The current address is unchanged.
  667.  
  668. `(1,$)wq FILE'
  669.      Writes the addressed lines to FILE, and then executes a `q'
  670.      command.
  671.  
  672. `(1,$)w !COMMAND'
  673.      Writes the addressed lines to the standard input of `!COMMAND',
  674.      (see the `!' command below).  The default filename and current
  675.      address are unchanged.
  676.  
  677. `(1,$)W FILE'
  678.      Appends the addressed lines to the end of FILE.  This is similar
  679.      to the `w' command, expect that the previous contents of file is
  680.      not clobbered.  The current address is unchanged.
  681.  
  682. `(.)x'
  683.      Copies (puts) the contents of the cut buffer to after the
  684.      addressed line.  The current address is set to the last line
  685.      copied.
  686.  
  687. `(.,.)y'
  688.      Copies (yanks) the addressed lines to the cut buffer.  The cut
  689.      buffer is overwritten by subsequent `y', `s', `j', `d', or `c'
  690.      commands.  The current address is unchanged.
  691.  
  692. `(.+1)z N'
  693.      Scrolls N lines at a time starting at addressed line.  If N is not
  694.      specified, then the current window size is used.  The current
  695.      address is set to the last line printed.
  696.  
  697. `! COMMAND'
  698.      Executes COMMAND via `sh (1)'.  If the first character of COMMAND
  699.      is `!', then it is replaced by text of the previous `!COMMAND'.
  700.      `ed' does not process COMMAND for backslash (`\') escapes.
  701.      However, an unescaped `%' is replaced by the default filename.
  702.      When the shell returns from execution, a `!' is printed to the
  703.      standard output.  The current line is unchanged.
  704.  
  705. `(.,.)#'
  706.      Begins a comment;  the rest of the line, up to a newline, is
  707.      ignored.  If a line address followed by a semicolon is given, then
  708.      the current address is set to that address.  Otherwise, the
  709.      current address is unchanged.
  710.  
  711. `($)='
  712.      Prints the line number of the addressed line.
  713.  
  714. `(.+1)newline'
  715.      Prints the addressed line, and sets the current address to that
  716.      line.
  717.  
  718. 
  719. File: ed.info,  Node: Limitations,  Next: Diagnostics,  Prev: Commands,  Up: Top
  720.  
  721. Limitations
  722. ***********
  723.  
  724.    The buffer files are kept in `/tmp/ed.*'.  If the terminal hangs up,
  725. `ed' attempts to write the buffer to file `ed.hup'.
  726.  
  727.    `ed' processes FILE arguments for backslash escapes, i.e., in a
  728. filename, any characters preceded by a backslash (`\') are interpreted
  729. literally.
  730.  
  731.    If a text (non-binary) file is not terminated by a newline character,
  732. then `ed' appends one on reading/writing it.  In the case of a binary
  733. file, `ed' does not append a newline on reading/writing.
  734.  
  735.    Per line overhead: 4 `int's.
  736.  
  737. 
  738. File: ed.info,  Node: Diagnostics,  Prev: Limitations,  Up: Top
  739.  
  740. Diagnostics
  741. ***********
  742.  
  743.    When an error occurs, if `ed''s input is from a regular file or here
  744. document, then it exits, otherwise it prints a `?' and returns to
  745. command mode.  An explanation of the last error can be printed with the
  746. `h' (help) command.
  747.  
  748. If the `u' (undo) command occurs in a global command list, then the
  749. command list is executed only once.
  750.  
  751.    Attempting to quit `ed' or edit another file before writing a
  752. modified buffer results in an error.  If the command is entered a
  753. second time, it succeeds, but any changes to the buffer are lost.
  754.  
  755.    `ed' exits with 0 if no errors occurred; otherwise >0.
  756.  
  757.  
  758. 
  759. Tag Table:
  760. Node: Top894
  761. Node: Intro1524
  762. Node: Invoking ed7498
  763. Node: Line addressing8535
  764. Node: Regular expressions11591
  765. Node: Commands16977
  766. Node: Limitations27863
  767. Node: Diagnostics28481
  768. 
  769. End Tag Table
  770.