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