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