OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / GNU_ed / original / man1 / ed.1
1 .TH ED 1 "10 November 1994"
2 .SH NAME
3 ed, red \- text editor
4 .SH SYNOPSIS
5 ed [-] [-Gs] [-p \fIstring\fR] [\fIfile\fR]
6 .LP
7 red [-] [-Gs] [-p \fIstring\fR] [\fIfile\fR]
8 .SH DESCRIPTION
9 .B ed
10 is a line-oriented text editor.
11 It is used to create, display, modify and otherwise manipulate text
12 files.
13 .B red
14 is a restricted
15 .BR ed :
16 it can only edit files in the current
17 directory and cannot execute shell commands.
18
19 If invoked with a
20 .I file
21 argument, then a copy of
22 .I file
23 is read into the editor's buffer.
24 Changes are made to this copy and not directly to
25 .I file
26 itself.
27 Upon quitting
28 .BR ed ,
29 any changes not explicitly saved  with a
30 .I `w'
31 command are lost.
32
33 Editing is done in two distinct modes:
34 .I command
35 and
36 .IR input .
37 When first invoked,
38 .B ed
39 is in command mode.
40 In this mode commands are read from the standard input and
41 executed to manipulate the contents of the editor buffer.
42 A typical command might look like:
43 .sp
44 .RS
45 ,s/\fIold\fR/\fInew\fR/g
46 .RE
47 .sp
48 which replaces all occurences of the string
49 .I old
50 with
51 .IR new .
52
53 When an input command, such as
54 .I `a'
55 (append),
56 .I `i'
57 (insert) or
58 .I `c'
59 (change), is given,
60 .B ed
61 enters input mode.  This is the primary means
62 of adding text to a file.
63 In this mode, no commands are available;
64 instead, the standard input is written
65 directly to the editor buffer.  Lines consist of text up to and
66 including a
67 .IR newline
68 character.
69 Input mode is terminated by
70 entering a single period  (\fI.\fR) on a line.
71
72 All
73 .B ed
74 commands operate on whole lines or ranges of lines; e.g.,
75 the
76 .I `d'
77 command deletes lines; the
78 .I `m'
79 command moves lines, and so on.
80 It is possible to modify only a portion of a line by means of replacement,
81 as in the example above.  However even here, the
82 .I `s'
83 command is applied to whole lines at a time.
84
85 In general,
86 .B ed
87 commands consist of zero or more line addresses, followed by a single
88 character command and possibly additional parameters; i.e.,
89 commands have the structure:
90 .sp
91 .RS
92 .I [address [,address]]command[parameters]
93 .RE
94 .sp
95 The address(es) indicate the line or range of lines to be affected by the
96 command.  If fewer addresses are given than the command accepts, then
97 default addresses are supplied.
98
99 .SS OPTIONS
100 .TP 8
101 -G
102 Forces backwards compatibility.  Affects the commands
103 .IR `G' ,
104 .IR `V' ,
105 .IR `f' ,
106 .IR `l' ,
107 .IR `m' ,
108 .IR `t' ,
109 and
110 .IR `!!' .
111 .TP 8
112 -s
113 Suppresses diagnostics. This should be used if
114 .BR ed 's
115 standard input is from a script.
116
117 .TP 8
118 .RI \-p \ string
119 Specifies a command prompt.  This may be toggled on and off with the
120 .I `P'
121 command.
122
123 .TP 8
124 .I file
125 Specifies the name of a file to read.  If
126 .I file
127 is prefixed with a
128 bang (!), then it is interpreted as a shell command.  In this case,
129 what is read is
130 the standard output of
131 .I file
132 executed via
133 .IR sh (1).
134 To read a file whose name begins with a bang, prefix the
135 name with a backslash (\e).
136 The default filename is set to
137 .I file
138 only if it is not prefixed with a bang.
139
140 .SS LINE ADDRESSING
141 An address represents the number of a line in the buffer.
142 .B ed
143 maintains a
144 .I current address
145 which is
146 typically supplied to commands as the default address when none is specified.
147 When a file is first read,  the current address is set to the last line
148 of the file.  In general, the current address is set to the last line
149 affected by a command.
150
151 A line address is
152 constructed from one of the bases in the list below, optionally followed
153 by a numeric offset.  The offset may include any combination
154 of digits, operators (i.e.,
155 .IR + ,
156 .I -
157 and
158 .IR ^ )
159 and whitespace.
160 Addresses are read from left to right, and their values are computed
161 relative to the current address.
162
163 One exception to the rule that addresses represent line numbers is the
164 address
165 .I 0
166 (zero).
167 This means "before the first line,"
168 and is legal wherever it makes sense.
169
170 An address range is two addresses separated either by a comma or
171 semicolon. The value of the first address in a range cannot exceed the
172 value of the the second.  If only one address is given in a range, then
173 the second address is set to the given address.  If an
174 .IR n- tuple
175 of addresses is given where
176 .I n > 2,
177 then the corresponding range is determined by the last two addresses in
178 the
179 .IR n- tuple.
180 If only one address is expected, then the last address is used.
181
182 Each address in a comma-delimited range is interpreted relative to the
183 current address.  In a semicolon-delimited range, the first address is
184 used to set the current address, and the second address is interpreted
185 relative to the first.
186
187
188 The following address symbols are recognized.
189
190 .TP 8
191 \&.
192 The current line (address) in the buffer.
193
194 .TP 8
195 $
196 The last line in the buffer.
197
198 .TP 8
199 n
200 The
201 .IR n th,
202 line in the buffer
203 where
204 .I n
205 is a number in the range
206 .I [0,$].
207
208 .HP
209 -
210 .TP 8
211 ^
212 The previous line.
213 This is equivalent to
214 .I -1
215 and may be repeated with cumulative effect.
216
217 .HP
218 -\fIn\fR
219 .TP 8
220 ^\fIn\fR
221 The
222 .IR n th
223 previous line, where
224 .I n
225 is a non-negative number.
226
227 .TP 8
228 +
229 The
230 next line.
231 This is equivalent to
232 .I +1
233 and may be repeated with cumulative effect.
234
235 .HP
236 +\fIn\fR
237 .TP 8
238 whitespace \fIn\fR
239 The
240 .IR n th
241 next line, where
242 .I n
243 is a non-negative number.
244 .I Whitespace
245 followed by a number
246 .I n
247 is interpreted as
248 .IR +n .
249
250 .HP
251 ,
252 .TP 8
253 %
254 The first through last lines in the buffer.  This is equivalent to
255 the address range
256 .I 1,$.
257
258 .TP 8
259 ;
260 The current through last lines in the buffer.  This is equivalent to
261 the address range
262 .I .,$.
263
264 .TP 8
265 .RI / re/
266 The
267 next line containing the regular expression
268 .IR re .
269 The search wraps to the beginning of the buffer and continues down to the
270 current line, if necessary.
271 // repeats the last search.
272
273 .TP 8
274 .RI ? re?
275 The
276 previous line containing the regular expression
277 .IR re .
278 The search wraps to the end of the buffer and continues up to the
279 current line, if necessary.
280 ?? repeats the last search.
281
282 .TP 8
283 .RI \' lc
284 The
285 line previously marked by a
286 .I `k'
287 (mark) command, where
288 .I lc
289 is a lower case letter.
290
291 .SS REGULAR EXPRESSIONS
292 Regular expressions are patterns used in selecting text.
293 For example, the
294 .B ed
295 command
296 .sp
297 .RS
298 g/\fIstring\fR/
299 .RE
300 .sp
301 prints all lines containing
302 .IR string .
303 Regular expressions are also
304 used by the
305 .I `s'
306 command for selecting old text to be replaced with new.
307
308 In addition to a specifying string literals, regular expressions can
309 represent
310 classes of strings.  Strings thus represented are said to be matched
311 by the corresponding regular expression.
312 If it is possible for a regular expression
313 to match several strings in a line, then the left-most longest match is
314 the one selected.
315
316 The following symbols are used in constructing regular expressions:
317
318 .TP 8
319 c
320 Any character
321 .I c
322 not listed below, including `{', '}', `(', `)', `<' and `>',
323 matches itself.
324
325 .TP 8
326 \e\fIc\fR
327 A backslash-escaped character
328 .IR c
329 other than `{', '}', `(', `)', `<', `>',
330 `b', 'B', `w', `W', `+', and `?'
331 matches itself.
332
333 .TP 8
334 \fR.\fR
335 Matches any single character.
336
337 .TP 8
338 .I [char-class]
339 Matches any single character in
340 .IR char-class .
341 To include a  `]'
342 in
343 .IR char-class ,
344 it must be the first character.
345 A range of characters may be specified by separating the end characters
346 of the range with a `-', e.g., `a-z' specifies the lower case characters.
347 The following literal expressions can also be used in
348 .I char-class
349 to specify sets of characters:
350 .sp
351 \ \ [:alnum:]\ \ [:cntrl:]\ \ [:lower:]\ \ [:space:]
352 .PD 0
353 \ \ [:alpha:]\ \ [:digit:]\ \ [:print:]\ \ [:upper:]
354 .PD 0
355 \ \ [:blank:]\ \ [:graph:]\ \ [:punct:]\ \ [:xdigit:]
356 .sp
357 If `-' appears as the first or last
358 character of
359 .IR char-class ,
360 then it matches itself.
361 All other characters in
362 .I char-class
363 match themselves.
364 .sp
365 Patterns in
366 .I char-class
367 of the form:
368 .sp
369 \ \ [.\fIcol-elm\fR.] or,
370 .PD 0
371 \ \ [=\fIcol-elm\fR=]
372 .sp
373 where
374 .I col-elm
375 is a
376 .I collating element
377 are interpreted according to
378 .IR locale (5)
379 (not currently supported).
380 See
381 .IR regex (3)
382 for an explanation of these constructs.
383
384 .TP 8
385 [^\fIchar-class\fR]
386 Matches any single character, other than newline, not in
387 .IR char-class .
388 .IR char-class
389 is defined
390 as above.
391
392 .TP 8
393 ^
394 If `^' is the first character of a regular expression, then it
395 anchors the regular expression to the beginning of a line.
396 Otherwise, it matches itself.
397
398 .TP 8
399 $
400 If `$' is the last character of a regular expression, it
401 anchors the regular expression to the end of a line.
402 Otherwise, it matches itself.
403
404 .TP 8
405 \e(\fIre\fR\e)
406 Defines a (possibly null) subexpression
407 .IR re .
408 Subexpressions may be nested.
409 A subsequent backreference of the form `\e\fIn\fR', where
410 .I n
411 is a number in the range [1,9], expands to the text matched by the
412 .IR n th
413 subexpression.
414 For example, the regular expression `\e(a.c\e)\e1' matches the
415 string `abcabc', but not `abcadc'.
416 Subexpressions are ordered relative to
417 their left delimiter.
418
419 .TP 8
420 *
421 Matches the single character regular expression or subexpression
422 immediately preceding it zero or more times.  If '*' is the first
423 character of a regular expression or subexpression, then it matches
424 itself.  The `*' operator sometimes yields unexpected results.
425 For example, the regular expression `b*' matches the beginning of
426 the string `abbb', as opposed to the substring `bbb', since a null match
427 is the only left-most match.
428
429 .HP
430 \fR\e{\fIn,m\fR\e}\fR
431 .HP
432 \fR\e{\fIn,\fR\e}\fR
433 .TP 8
434 \fR\e{\fIn\fR\e}\fR
435 Matches the single character regular expression or subexpression
436 immediately preceding it at least
437 .I n
438 and at most
439 .I m
440 times.
441 If
442 .I m
443 is omitted, then it matches at least
444 .I n
445 times.
446 If the comma is also omitted, then it matches exactly
447 .I n
448 times.  If  any of these forms occurs first in a regular expression or
449 subexpression, then it is interpreted literally (i.e., the regular
450 expression `\e{2\e}' matches the string `{2}', and so on).
451
452 .HP
453 \e<
454 .TP 8
455 \fR\e>\fR
456 Anchors the single character regular expression or subexpression
457 immediately following it to the beginning (\e<) or ending
458 (\e>) of a \fIword\fR, i.e., in ASCII, a maximal string of alphanumeric
459 characters, including the underscore (_).
460
461
462 .LP
463 The following extended operators are preceded by a backslash (\e) to
464 distinguish them from traditional
465 .B ed
466 syntax.
467
468 .HP
469 \fR\e`\fR
470 .TP 8
471 \fR\e'\fR
472 Unconditionally matches the beginning (\e`) or ending (\e') of a line.
473
474 .TP 8
475 \fR\e?\fR
476 Optionally matches the single character regular expression or subexpression
477 immediately preceding it.  For example, the regular expression `a[bd]\e?c'
478 matches the strings `abc', `adc' and `ac'.  If \e? occurs at the beginning
479 of a regular expressions or subexpression, then it matches a literal `?'.
480
481 .TP 8
482 \fR\e+\fR
483 Matches the single character regular expression or subexpression
484 immediately preceding it one or more times.  So the regular expression
485 `a+' is shorthand for `aa*'.  If \e+ occurs at the beginning of a
486 regular expression or subexpression, then it matches a literal `+'.
487
488
489 .TP 8
490 \fR\eb\fR
491 Matches the beginning or ending (null string) of a word.  Thus the regular
492 expression `\ebhello\eb' is equivalent to `\e<hello\e>'.  However, `\eb\eb'
493 is a valid regular expression whereas `\e<\e>' is not.
494
495 .TP 8
496 \fR\eB\fR
497 Matches (a null string) inside a word.
498
499 .TP 8
500 \fR\ew\fR
501 Matches any character in a word.
502
503 .TP 8
504 \fR\eW\fR
505 Matches any character not in a word.
506
507 .SS COMMANDS
508 All
509 .B ed
510 commands are single characters, though some require additonal parameters.
511 If a command's parameters extend over several lines, then
512 each line except for the last
513 must be terminated with a backslash (\e).
514
515 In general, at most one command is allowed per line.
516 However, most commands accept a print suffix, which is any of
517 .I `p'
518 (print),
519 .I `l'
520 (list) ,
521 or
522 .I `n'
523 (enumerate),
524 to print the last line affected by the command.
525
526 An interrupt (typically ^C) has the effect of aborting the current command
527 and returning the editor to command mode.
528
529 .B ed
530 recognizes the following commands.  The commands are shown together with
531 the default address or address range supplied if none is
532 specified (in parenthesis).
533
534 .TP 8
535 (.)a
536 Appends text to the buffer after the addressed line, which may be the
537 address 0 (zero).  Text is entered in input mode.  The current address is
538 set to last line entered.
539
540 .TP 8
541 (.,.)c
542 Changes lines in the buffer.  The addressed lines are deleted
543 from the buffer, and text is appended in their place.
544 Text is entered in input mode.
545 The current address is set to last line entered.
546
547 .TP 8
548 (.,.)d
549 Deletes the addressed lines from the buffer.
550 If there is a line after the deleted range, then the current address is set
551 to this line. Otherwise the current address is set to the line
552 before the deleted range.
553
554 .TP 8
555 .RI e \ file
556 Edits
557 .IR file ,
558 and sets the default filename.
559 If
560 .I file
561 is not specified, then the  default filename is used.
562 Any lines in the buffer are deleted before
563 the new file is read.
564 The current address is set to the last line read.
565
566 .TP 8
567 .RI e \ !command
568 Edits the standard output of
569 .IR `!command' ,
570 (see
571 .RI ! command
572 below).
573 The default filename is unchanged.
574 Any lines in the buffer are deleted before the output of
575 .I command
576 is read.
577 The current address is set to the last line read.
578
579 .TP 8
580 .RI E \ file
581 Edits
582 .I file
583 unconditionally.
584 This is similar to the
585 .I e
586 command,
587 except that unwritten changes are discarded without warning.
588 The current address is set to the last line read.
589
590 .TP 8
591 .RI f \ file
592 Sets the default filename to
593 .IR file .
594 If
595 .I file
596 is not specified, then the default unescaped filename is printed.
597
598 .TP 8
599 .RI (1,$)g /re/command-list
600 Applies
601 .I command-list
602 to each of the addressed lines matching a regular expression
603 .IR re .
604 The current address is set to the
605 line currently matched before
606 .I command-list
607 is executed.
608 At the end of the
609 .I `g'
610 command, the current address is set to the last line affected by
611 .IR command-list .
612
613 Each command in
614 .I command-list
615 must be on a separate line,
616 and every line except for the last must be terminated by a backslash
617 (\e).
618 Any commands are allowed, except for
619 .IR `g' ,
620 .IR `G' ,
621 .IR `v' ,
622 and
623 .IR `V' .
624 A newline alone in
625 .I command-list
626 is equivalent to a
627 .I `p'
628 command.
629
630 .TP 8
631 .RI (1,$)G /re/
632 Interactively edits the addressed lines matching a regular expression
633 .IR re.
634 For each matching line,
635 the line is printed,
636 the current address is set,
637 and the user is prompted to enter a
638 .IR command-list .
639 At the end of the
640 .I `G'
641 command, the current address
642 is set to the last line affected by (the last)
643 .IR command-list .
644
645 The format of
646 .I command-list
647 is the same as that of the
648 .I `g'
649 command.  A newline alone acts as a null command list.
650 A single `&' repeats the last non-null command list.
651
652 .TP 8
653 H
654 Toggles the printing of error explanations.
655 By default, explanations are not printed.
656 It is recommended that ed scripts begin with this command to
657 aid in debugging.
658
659 .TP 8
660 h
661 Prints an explanation of the last error.
662
663 .TP 8
664 (.)i
665 Inserts text in the buffer before the current line.
666 Text is entered in input mode.
667 The current address is set to the last line entered.
668
669 .TP 8
670 (.,.+1)j
671 Joins the addressed lines.  The addressed lines are
672 deleted from the buffer and replaced by a single
673 line containing their joined text.
674 The current address is set to the resultant line.
675
676 .TP 8
677 .RI (.)k lc
678 Marks a line with a lower case letter
679 .IR lc .
680 The  line can then be addressed as
681 .I 'lc
682 (i.e., a single quote followed by
683 .I lc
684 ) in subsequent commands.  The mark is not cleared until the line is
685 deleted or otherwise modified.
686
687 .TP 8
688 (.,.)l
689 Prints the addressed lines unambiguously.  If invoked from a terminal,
690 .B ed
691 pauses at the end of each page until a newline is entered.
692 The current address is set to the last line printed.
693
694 .TP 8
695 (.,.)m(.)
696 Moves lines in the buffer.  The addressed lines are moved to after the
697 right-hand destination address, which may be the address
698 .IR 0
699 (zero).
700 The current address is set to the
701 last line moved.
702
703 .TP 8
704 (.,.)n
705 Prints the addressed lines along with
706 their line numbers.  The current address is set to the last line
707 printed.
708
709 .TP 8
710 (.,.)p
711 Prints the addressed lines.    If invoked from a terminal,
712 .B ed
713 pauses at the end of each page until a newline is entered.
714 The current address is set to the last line
715 printed.
716
717 .TP 8
718 P
719 Toggles the command prompt on and off.
720 Unless a prompt was specified by with command-line option
721 \fI-p string\fR, the command prompt is by default turned off.
722
723 .TP 8
724 q
725 Quits ed.
726
727 .TP 8
728 Q
729 Quits ed unconditionally.
730 This is similar to the
731 .I q
732 command,
733 except that unwritten changes are discarded without warning.
734
735 .TP 8
736 .RI ($)r \ file
737 Reads
738 .I file
739 to after the addressed line.  If
740 .I file
741 is not specified, then the default
742 filename is used.  If there was no default filename prior to the command,
743 then the default filename is set to
744 .IR file .
745 Otherwise, the default filename is unchanged.
746 The current address is set to the last line read.
747
748 .TP 8
749 .RI ($)r \ !command
750 Reads
751 to after the addressed line
752 the standard output of
753 .IR `!command' ,
754 (see the
755 .RI ! command
756 below).
757 The default filename is unchanged.
758 The current address is set to the last line read.
759
760 .HP
761 .RI (.,.)s /re/replacement/
762 .HP
763 .RI (.,.)s  /re/replacement/\fRg\fR
764 .HP
765 .RI (.,.)s  /re/replacement/n
766 .br
767 Replaces text in the addressed lines
768 matching a regular expression
769 .I re
770 with
771 .IR replacement .
772 By default, only the first match in each line is replaced.
773 If the
774 .I `g'
775 (global) suffix is given, then every match to be replaced.
776 The
777 .I `n'
778 suffix, where
779 .I n
780 is a postive number, causes only the
781 .IR n th
782 match to be replaced.
783 It is an error if no substitutions are performed on any of the addressed
784 lines.
785 The current address is set the last line affected.
786
787 .I re
788 and
789 .I replacement
790 may be delimited by any character other than space and newline
791 (see the
792 .I `s'
793 command below).
794 If one or two of the last delimiters is omitted, then the last line
795 affected is printed as though the print suffix
796 .I `p'
797 were specified.
798
799
800 An unescaped `&' in
801 .I replacement
802 is replaced by the currently matched text.
803 The character sequence
804 \fI`\em'\fR,
805 where
806 .I m
807 is a number in the range [1,9], is replaced by the
808 .IR m th
809 backreference expression of the matched text.
810 If
811 .I replacement
812 consists of a single `%', then
813 .I replacement
814 from the last substitution is used.
815 Newlines may be embedded in
816 .I replacement
817 if they are escaped with a backslash (\e).
818
819 .TP 8
820 (.,.)s
821 Repeats the last substitution.
822 This form of the
823 .I `s'
824 command accepts a count suffix
825 .IR `n' ,
826 or any combination of the characters
827 .IR `r' ,
828 .IR `g' ,
829 and
830 .IR `p' .
831 If a count suffix
832 .I `n'
833 is given, then only the
834 .IR n th
835 match is replaced.
836 The
837 .I `r'
838 suffix causes
839 the regular expression of the last search to be used instead of the
840 that of the last substitution.
841 The
842 .I `g'
843 suffix toggles the global suffix of the last substitution.
844 The
845 .I `p'
846 suffix toggles the print suffix of the last substitution
847 The current address is set to the last line affected.
848
849 .TP 8
850 (.,.)t(.)
851 Copies (i.e., transfers) the addressed lines to after the right-hand
852 destination address, which may be the address
853 .IR 0
854 (zero).
855 The current address is set to the last line
856 copied.
857
858 .TP 8
859 u
860 Undoes the last command and restores the current address
861 to what it was before the command.
862 The global commands
863 .IR `g' ,
864 .IR `G' ,
865 .IR `v' ,
866 and
867 .IR `V' .
868 are treated as a single command by undo.
869 .I `u'
870 is its own inverse.
871
872 .TP 8
873 .RI (1,$)v /re/command-list
874 Applies
875 .I command-list
876 to each of the addressed lines not matching a regular expression
877 .IR re .
878 This is similar to the
879 .I `g'
880 command.
881
882 .TP 8
883 .RI (1,$)V /re/
884 Interactively edits the addressed lines not matching a regular expression
885 .IR re.
886 This is similar to the
887 .I `G'
888 command.
889
890 .TP 8
891 .RI (1,$)w \ file
892 Writes the addressed lines to
893 .IR file .
894 Any previous contents of
895 .I file
896 is lost without warning.
897 If there is no default filename, then the default filename is set to
898 .IR file,
899 otherwise it is unchanged.  If no filename is specified, then the default
900 filename is used.
901 The current address is unchanged.
902
903 .TP 8
904 .RI (1,$)wq \ file
905 Writes the addressed lines to
906 .IR file ,
907 and then executes a
908 .I `q'
909 command.
910
911 .TP 8
912 .RI (1,$)w \ !command
913 Writes the addressed lines to the standard input of
914 .IR `!command' ,
915 (see the
916 .RI ! command
917 below).
918 The default filename and current address are unchanged.
919
920 .TP 8
921 .RI (1,$)W \ file
922 Appends the addressed lines to the end of
923 .IR file .
924 This is similar to the
925 .I `w'
926 command, expect that the previous contents of file is not clobbered.
927 The current address is unchanged.
928
929 .TP 8
930 (.)x
931 Copies (puts) the contents of the cut buffer to after the addressed line.
932 The current address is set to the last line copied.
933
934 .TP 8
935 (.,.)y
936 Copies (yanks) the addressed lines to the cut buffer.
937 The cut buffer is overwritten by subsequent
938 .IR `y' ,
939 .IR `s' ,
940 .IR `j' ,
941 .IR `d' ,
942 or
943 .I `c'
944 commands.
945 The current address is unchanged.
946
947 .TP 8
948 .RI (.+1)z n
949 Scrolls
950 .I n
951 lines at a time starting at addressed line.  If
952 .I n
953 is not specified, then the current window size is used.
954 The current address is set to the last line printed.
955
956 .TP 8
957 .RI ! command
958 Executes
959 .I command
960 via
961 .IR sh (1).
962 If the first character of
963 .I command
964 is `!', then it is replaced by text of the
965 previous
966 .IR `!command' .
967 .B ed
968 does not process
969 .I command
970 for backslash (\e) escapes.
971 However, an unescaped
972 .I `%'
973 is replaced by the default filename.
974 When the shell returns from execution, a `!'
975 is printed to the standard output.
976 The current line is unchanged.
977
978 .TP 8
979 (.,.)#
980 Begins a comment;  the rest of the line, up to a newline, is ignored.
981 If a line address followed by a semicolon is given, then the
982 current address is set to that address.  Otherwise, the current address
983 is unchanged.
984
985 .TP 8
986 ($)=
987 Prints the line number of the addressed line.
988
989 .TP 8
990 (.+1)newline
991 Prints the addressed line, and sets the current address to
992 that line.
993
994 .SH FILES
995 .TP 20
996 /tmp/ed.*
997 Buffer file
998 .PD 0
999 .TP 20
1000 ed.hup
1001 The file to which
1002 .B ed
1003 attempts to write the  buffer if the terminal hangs up.
1004
1005 .SH SEE ALSO
1006
1007 .IR vi (1),
1008 .IR sed (1),
1009 .IR regex (3),
1010 .IR sh (1).
1011
1012 USD:12-13
1013
1014 B. W. Kernighan and P. J. Plauger,
1015 .I Software Tools in Pascal ,
1016 Addison-Wesley, 1981.
1017
1018 .SH LIMITATIONS
1019 .B ed
1020 processes
1021 .I file
1022 arguments for backslash escapes, i.e.,  in a filename,
1023 any characters preceded by a backslash (\e) are
1024 interpreted literally.
1025
1026 If a text (non-binary) file is not terminated by a newline character,
1027 then
1028 .B ed
1029 appends one on reading/writing it.  In the case of a binary file,
1030 .B ed
1031 does not append a newline on reading/writing.
1032
1033 per line overhead: 4 ints
1034
1035 .SH DIAGNOSTICS
1036 When an error occurs,
1037 if
1038 .BR ed 's
1039 input is from a regular file or here document, then it
1040 exits, otherwise it
1041 prints a `?' and returns to command mode.
1042 An explanation of the last error can be
1043 printed with the
1044 .I `h'
1045 (help) command.
1046
1047 Attempting to quit
1048 .B ed
1049 or edit another file before writing a modified buffer
1050 results in an error.
1051 If the command is entered a second time, it succeeds,
1052 but any changes to the buffer are lost.
1053
1054 .B ed
1055 exits with 0 if no errors occurred; otherwise >0.