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