Commit | Line | Data |
---|---|---|
9314db29 KT |
1 | .TH ED 1 |
2 | .if t .ds q \(aa | |
3 | .if n .ds q ' | |
4 | .SH NAME | |
5 | ed \- text editor | |
6 | .SH SYNOPSIS | |
7 | .B ed | |
8 | [ | |
9 | .B \- | |
10 | ] [ | |
11 | .B \-x | |
12 | ] [ name ] | |
13 | .SH DESCRIPTION | |
14 | .I Ed | |
15 | is the standard text editor. | |
16 | .PP | |
17 | If a | |
18 | .I name | |
19 | argument is given, | |
20 | .I ed | |
21 | simulates an | |
22 | .I e | |
23 | command (see below)\| on the named file; that is to say, | |
24 | the file is read into | |
25 | .I ed's | |
26 | buffer so that it can be edited. | |
27 | If | |
28 | .B \-x | |
29 | is present, an | |
30 | .I x | |
31 | command is simulated first to handle an encrypted file. | |
32 | The optional | |
33 | .B \- | |
34 | suppresses the printing | |
35 | of character counts by | |
36 | .I e, | |
37 | .I r, | |
38 | and | |
39 | .I w | |
40 | commands. | |
41 | .PP | |
42 | .I Ed | |
43 | operates on a copy of any file it is editing; changes made | |
44 | in the copy have no effect on the file until a | |
45 | .IR w "" | |
46 | (write)\| | |
47 | command is given. | |
48 | The copy of the text being edited resides | |
49 | in a temporary file called the | |
50 | .IR buffer . | |
51 | .PP | |
52 | Commands to | |
53 | .I ed | |
54 | have a simple and regular structure: zero or | |
55 | more | |
56 | .I addresses | |
57 | followed by a single character | |
58 | .I command, | |
59 | possibly | |
60 | followed by parameters to the command. | |
61 | These addresses specify one or more lines in the buffer. | |
62 | Missing addresses are supplied by default. | |
63 | .PP | |
64 | In general, only one command may appear on a line. | |
65 | Certain commands allow the | |
66 | addition of text to the buffer. | |
67 | While | |
68 | .I ed | |
69 | is accepting text, it is said | |
70 | to be in | |
71 | .I "input mode." | |
72 | In this mode, no commands are recognized; | |
73 | all input is merely collected. | |
74 | Input mode is left by typing a period `\fB.\fR' alone at the | |
75 | beginning of a line. | |
76 | .PP | |
77 | .I Ed | |
78 | supports a limited form of | |
79 | .I "regular expression" | |
80 | notation. | |
81 | A regular expression specifies | |
82 | a set of strings of characters. | |
83 | A member of this set of strings is said to be | |
84 | .I matched | |
85 | by the regular expression. | |
86 | In the following specification for regular expressions | |
87 | the word `character' means any character but newline. | |
88 | .IP 1. | |
89 | Any character except a special character | |
90 | matches itself. | |
91 | Special characters are | |
92 | the regular expression delimiter plus | |
93 | .RB \e\|[\| . | |
94 | and sometimes ^\|*\|$. | |
95 | .IP 2. | |
96 | A | |
97 | .B . | |
98 | matches any character. | |
99 | .IP 3. | |
100 | A \e followed by any character except a digit or (\|) matches that character. | |
101 | .IP 4. | |
102 | A nonempty string | |
103 | .I s | |
104 | bracketed | |
105 | .RI [ \|s\| ] | |
106 | (or | |
107 | .RI [^ s\| ]) | |
108 | matches any character in (or not in) | |
109 | .I s. | |
110 | In | |
111 | .I s, | |
112 | \e has no special meaning, and ] may only appear as | |
113 | the first letter. | |
114 | A substring | |
115 | .I a\-b, | |
116 | with | |
117 | .I a | |
118 | and | |
119 | .I b | |
120 | in ascending ASCII order, stands for the inclusive | |
121 | range of ASCII characters. | |
122 | .IP 5. | |
123 | A regular expression of form 1-4 followed by * matches a sequence of | |
124 | 0 or more matches of the regular expression. | |
125 | .IP 6. | |
126 | A regular expression, | |
127 | .I x, | |
128 | of form 1-8, bracketed | |
129 | .RI \e( \|x\| \e) | |
130 | matches what | |
131 | .I x | |
132 | matches. | |
133 | .IP 7. | |
134 | A \e followed by a digit | |
135 | .I n | |
136 | matches a copy of the string that the | |
137 | bracketed regular expression beginning with the | |
138 | .IR n th | |
139 | \e( matched. | |
140 | .IP 8. | |
141 | A regular expression of form 1-8, | |
142 | .I x, | |
143 | followed by a regular expression of form 1-7, | |
144 | .I y | |
145 | matches a match for | |
146 | .I x | |
147 | followed by a match for | |
148 | .I y, | |
149 | with the | |
150 | .I x | |
151 | match being as long as possible while still permitting a | |
152 | .I y | |
153 | match. | |
154 | .IP 9. | |
155 | A regular expression of form 1-8 preceded by ^ | |
156 | (or followed by $), is constrained to matches that | |
157 | begin at the left (or end at the right) end of a line. | |
158 | .IP 10. | |
159 | A regular expression of form 1-9 picks out the | |
160 | longest among the leftmost matches in a line. | |
161 | .IP 11. | |
162 | An empty regular expression stands for a copy of the | |
163 | last regular expression encountered. | |
164 | .PP | |
165 | Regular expressions are used in addresses to specify | |
166 | lines and in one command | |
167 | (see | |
168 | .I s | |
169 | below)\| | |
170 | to specify a portion of a line which is to be replaced. | |
171 | If it is desired to use one of | |
172 | the regular expression metacharacters as an ordinary | |
173 | character, that character may be preceded by `\e'. | |
174 | This also applies to the character bounding the regular | |
175 | expression (often `/')\| and to `\e' itself. | |
176 | .PP | |
177 | To understand addressing in | |
178 | .I ed | |
179 | it is necessary to know that at any time there is a | |
180 | .I "current line." | |
181 | Generally speaking, the current line is | |
182 | the last line affected by a command; however, | |
183 | the exact effect on the current line | |
184 | is discussed under the description of | |
185 | the command. | |
186 | Addresses are constructed as follows. | |
187 | .TP | |
188 | 1. | |
189 | The character `\fB.\fR' addresses the current line. | |
190 | .TP | |
191 | 2. | |
192 | The character `$' addresses the last line of the buffer. | |
193 | .TP | |
194 | 3. | |
195 | A decimal number | |
196 | .I n | |
197 | addresses the | |
198 | .IR n -th | |
199 | line of the buffer. | |
200 | .TP | |
201 | 4. | |
202 | `\(fm\fIx\fR' addresses the line marked with the name | |
203 | .IR x , | |
204 | which must be a lower-case letter. | |
205 | Lines are marked with the | |
206 | .I k | |
207 | command described below. | |
208 | .TP | |
209 | 5. | |
210 | A regular expression enclosed in slashes `/' addresses | |
211 | the line found by searching forward from the current line | |
212 | and stopping at the first line containing a | |
213 | string that matches the regular expression. | |
214 | If necessary the search wraps around to the beginning of the | |
215 | buffer. | |
216 | .TP | |
217 | 6. | |
218 | A regular expression enclosed in queries `?' addresses | |
219 | the line found by searching backward from the current line | |
220 | and stopping at the first line containing | |
221 | a string that matches the regular expression. | |
222 | If necessary | |
223 | the search wraps around to the end of the buffer. | |
224 | .TP | |
225 | 7. | |
226 | An address followed by a plus sign `+' | |
227 | or a minus sign `\-' followed by a decimal number specifies that address plus | |
228 | (resp. minus)\| the indicated number of lines. | |
229 | The plus sign may be omitted. | |
230 | .TP | |
231 | 8. | |
232 | If an address begins with `+' or `\-' | |
233 | the addition or subtraction is taken with respect to the current line; | |
234 | e.g. `\-5' is understood to mean `\fB.\fR\-5'. | |
235 | .TP | |
236 | 9. | |
237 | If an address ends with `+' or `\-', | |
238 | then 1 is added (resp. subtracted). | |
239 | As a consequence of this rule and rule 8, | |
240 | the address `\-' refers to the line before the current line. | |
241 | Moreover, | |
242 | trailing | |
243 | `+' and `\-' characters | |
244 | have cumulative effect, so `\-\-' refers to the current | |
245 | line less 2. | |
246 | .TP | |
247 | 10. | |
248 | To maintain compatibility with earlier versions of the editor, | |
249 | the character `^' in addresses is | |
250 | equivalent to `\-'. | |
251 | .PP | |
252 | Commands may require zero, one, or two addresses. | |
253 | Commands which require no addresses regard the presence | |
254 | of an address as an error. | |
255 | Commands which accept one or two addresses | |
256 | assume default addresses when insufficient are given. | |
257 | If more addresses are given than such a command requires, | |
258 | the last one or two (depending on what is accepted)\| are used. | |
259 | .PP | |
260 | Addresses are separated from each other typically by a comma | |
261 | `\fB,\fR'. | |
262 | They may also be separated by a semicolon | |
263 | `\fB;\fR'. | |
264 | In this case the current line `\fB.\fR' is set to | |
265 | the previous address before the next address is interpreted. | |
266 | This feature can be used to determine the starting | |
267 | line for forward and backward searches (`/', `?')\|. | |
268 | The second address of any two-address sequence | |
269 | must correspond to a line following the line corresponding to the first address. | |
270 | .PP | |
271 | In the following list of | |
272 | .I ed | |
273 | commands, the default addresses | |
274 | are shown in parentheses. | |
275 | The parentheses are not part of | |
276 | the address, but are used to show that the given addresses are | |
277 | the default. | |
278 | .PP | |
279 | As mentioned, it is generally illegal for more than one | |
280 | command to appear on a line. | |
281 | However, most commands may be suffixed by `p' | |
282 | or by `l', in which case | |
283 | the current line is either | |
284 | printed or listed respectively | |
285 | in the way discussed below. | |
286 | .TP 5 | |
287 | .RB (\| .\| )\|a | |
288 | .br | |
289 | .ns | |
290 | .TP 5 | |
291 | <text> | |
292 | .br | |
293 | .ns | |
294 | .TP 5 | |
295 | .B . | |
296 | .br | |
297 | The append command reads the given text | |
298 | and appends it after the addressed line. | |
299 | `\fB.\fR' is left | |
300 | on the last line input, if there | |
301 | were any, otherwise at the addressed line. | |
302 | Address `0' is legal for this command; text is placed | |
303 | at the beginning of the buffer. | |
304 | .TP 5 | |
305 | .RB (\| .\| ,\ .\| )\|c | |
306 | .br | |
307 | .ns | |
308 | .TP 5 | |
309 | <text> | |
310 | .br | |
311 | .ns | |
312 | .TP 5 | |
313 | .B . | |
314 | .br | |
315 | The change | |
316 | command deletes the addressed lines, then accepts input | |
317 | text which replaces these lines. | |
318 | `\fB.\fR' is left at the last line input; if there were none, | |
319 | it is left at the line preceding the deleted lines. | |
320 | .TP 5 | |
321 | .RB (\| .\| ,\ .\| )\|d | |
322 | The delete command deletes the addressed lines from the buffer. | |
323 | The line originally after the last line deleted becomes the current line; | |
324 | if the lines deleted were originally at the end, | |
325 | the new last line becomes the current line. | |
326 | .TP 5 | |
327 | e filename | |
328 | The edit | |
329 | command causes the entire contents of the buffer to be deleted, | |
330 | and then the named file to be read in. | |
331 | `\fB.\fR' is set to the last line of the buffer. | |
332 | The number of characters read is typed. | |
333 | `filename' is remembered for possible use as a default file name | |
334 | in a subsequent | |
335 | .I r | |
336 | or | |
337 | .I w | |
338 | command. | |
339 | If `filename' is missing, the remembered name is used. | |
340 | .TP 5 | |
341 | E filename | |
342 | This command is the same as | |
343 | .I e, | |
344 | except that no diagnostic results when no | |
345 | .I w | |
346 | has been given since the last buffer alteration. | |
347 | .TP 5 | |
348 | f filename | |
349 | The filename command prints the currently remembered file name. | |
350 | If `filename' is given, | |
351 | the currently remembered file name is changed to `filename'. | |
352 | .TP 5 | |
353 | (1,$)\|g/regular expression/command list | |
354 | In the global | |
355 | command, the first step is to mark every line which matches | |
356 | the given regular expression. | |
357 | Then for every such line, the | |
358 | given command list is executed with `\fB.\fR' initially set to that line. | |
359 | A single command or the first of multiple commands | |
360 | appears on the same line with the global command. | |
361 | All lines of a multi-line list except the last line must be ended with `\e'. | |
362 | .I A, | |
363 | .I i, | |
364 | and | |
365 | .I c | |
366 | commands and associated input are permitted; | |
367 | the `\fB.\fR' terminating input mode may be omitted if it would be on the | |
368 | last line of the command list. | |
369 | The commands | |
370 | .I g | |
371 | and | |
372 | .I v | |
373 | are not permitted in the command list. | |
374 | .TP 5 | |
375 | .RB (\| .\| )\|i | |
376 | .ns | |
377 | .TP 5 | |
378 | <text> | |
379 | .br | |
380 | .ns | |
381 | .TP 5 | |
382 | .B . | |
383 | .br | |
384 | This command inserts the given text before the addressed line. | |
385 | `\fB.\fR' is left at the last line input, or, if there were none, | |
386 | at the line before the addressed line. | |
387 | This command differs from the | |
388 | .I a | |
389 | command only in the placement of the | |
390 | text. | |
391 | .TP 5 | |
392 | .RB (\| .\| ,\ . +1)\|j | |
393 | This command joins the addressed lines into a single line; | |
394 | intermediate newlines simply disappear. | |
395 | `\fB.\fR' is left at the resulting line. | |
396 | .TP 5 | |
397 | ( \fB. \fR)\|k\fIx\fR | |
398 | The mark command marks the addressed line with | |
399 | name | |
400 | .I x, | |
401 | which must be a lower-case letter. | |
402 | The address form `\(fm\fIx\fR' then addresses this line. | |
403 | .ne 2.5 | |
404 | .TP 5 | |
405 | .RB (\| .\| ,\ .\| )\|l | |
406 | The list command | |
407 | prints the addressed lines in an unambiguous way: | |
408 | non-graphic characters are | |
409 | printed in two-digit octal, | |
410 | and long lines are folded. | |
411 | The | |
412 | .I l | |
413 | command may be placed on the same line after any non-i/o | |
414 | command. | |
415 | .TP 5 | |
416 | .RB (\| .\| ,\ .\| )\|m\fIa | |
417 | The move command repositions the addressed lines after the line | |
418 | addressed by | |
419 | .IR a . | |
420 | The last of the moved lines becomes the current line. | |
421 | .TP 5 | |
422 | .RB (\| .\| ,\ .\| )\|p | |
423 | The print command prints the addressed lines. | |
424 | `\fB.\fR' | |
425 | is left at the last line printed. | |
426 | The | |
427 | .I p | |
428 | command | |
429 | may | |
430 | be placed on the same line after any non-i/o command. | |
431 | .TP | |
432 | .RB (\| .\| ,\ .\| )\|P | |
433 | This command is a synonym for | |
434 | .I p. | |
435 | .TP 5 | |
436 | q | |
437 | The quit command causes | |
438 | .I ed | |
439 | to exit. | |
440 | No automatic write | |
441 | of a file is done. | |
442 | .TP 5 | |
443 | Q | |
444 | This command is the same as | |
445 | .I q, | |
446 | except that no diagnostic results when no | |
447 | .I w | |
448 | has been given since the last buffer alteration. | |
449 | .TP 5 | |
450 | ($)\|r filename | |
451 | The read command | |
452 | reads in the given file after the addressed line. | |
453 | If no file name is given, | |
454 | the remembered file name, if any, is used | |
455 | (see | |
456 | .I e | |
457 | and | |
458 | .I f | |
459 | commands)\|. | |
460 | The file name is remembered if there was no | |
461 | remembered file name already. | |
462 | Address `0' is legal for | |
463 | .I r | |
464 | and causes the | |
465 | file to be read at the beginning of the buffer. | |
466 | If the read is successful, the number of characters | |
467 | read is typed. | |
468 | `\fB.\fR' is left at the last line read in from the file. | |
469 | .TP 5 | |
470 | (\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/replacement/ or, | |
471 | .br | |
472 | .ns | |
473 | .TP 5 | |
474 | (\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/replacement/g | |
475 | The substitute command searches each addressed | |
476 | line for an occurrence of the specified regular expression. | |
477 | On each line in which a match is found, | |
478 | all matched strings are replaced by the replacement specified, | |
479 | if the global replacement indicator `g' appears after the command. | |
480 | If the global indicator does not appear, only the first occurrence | |
481 | of the matched string is replaced. | |
482 | It is an error for the substitution to fail on all addressed lines. | |
483 | Any character other than space or new-line | |
484 | may be used instead of `/' to delimit the regular expression | |
485 | and the replacement. | |
486 | `\fB.\fR' is left at the last line substituted. | |
487 | .IP | |
488 | An ampersand `&' appearing in the replacement | |
489 | is replaced by the string matching the regular expression. | |
490 | The special meaning of `&' in this context may be | |
491 | suppressed by preceding it by `\e'. | |
492 | The characters | |
493 | .I `\|\en' | |
494 | where | |
495 | .I n | |
496 | is a digit, | |
497 | are replaced by the text matched by the | |
498 | .IR n -th | |
499 | regular subexpression | |
500 | enclosed between `\e(' and `\e)'. | |
501 | When | |
502 | nested, parenthesized subexpressions | |
503 | are present, | |
504 | .I n | |
505 | is determined by counting occurrences of `\e(' starting from the left. | |
506 | .IP | |
507 | Lines may be split by substituting new-line characters into them. | |
508 | The new-line in the | |
509 | replacement string | |
510 | must be escaped by preceding it by `\e'. | |
511 | .TP 5 | |
512 | .RB (\| .\| ,\ .\| )\|t\|\fIa | |
513 | This command acts just like the | |
514 | .I m | |
515 | command, except that a copy of the addressed lines is placed | |
516 | after address | |
517 | .I a | |
518 | (which may be 0). | |
519 | `\fB.\fR' is left on the last line of the copy. | |
520 | .TP 5 | |
521 | .RB (\| .\| ,\ .\| )\|u | |
522 | The undo command restores the preceding contents | |
523 | of the current line, which must be the last line | |
524 | in which a substitution was made. | |
525 | .TP 5 | |
526 | (1, $)\|v/regular expression/command list | |
527 | This command is the same as the global command | |
528 | .I g | |
529 | except that the command list is executed | |
530 | .I g | |
531 | with `\fB.\fR' initially set to every line | |
532 | .I except | |
533 | those | |
534 | matching the regular expression. | |
535 | .TP 5 | |
536 | (1, $)\|w filename | |
537 | .br | |
538 | The write command writes the addressed lines onto | |
539 | the given file. | |
540 | If the file does not exist, | |
541 | it is created mode 666 (readable and writable by everyone)\|. | |
542 | The file name is remembered if there was no | |
543 | remembered file name already. | |
544 | If no file name is given, | |
545 | the remembered file name, if any, is used | |
546 | (see | |
547 | .I e | |
548 | and | |
549 | .I f | |
550 | commands)\|. | |
551 | `\fB.\fR' is unchanged. | |
552 | If the command is successful, the number of characters written is | |
553 | printed. | |
554 | .TP | |
555 | (1,$)W filename | |
556 | This command is the same as | |
557 | .I w, | |
558 | except that the addressed lines are appended to the file. | |
559 | .TP 5 | |
560 | x | |
561 | A key string is demanded from the standard input. | |
562 | Later | |
563 | .I r, e | |
564 | and | |
565 | .I w | |
566 | commands will encrypt and decrypt the text | |
567 | with this key by the algorithm of | |
568 | .IR crypt (1). | |
569 | An explicitly empty key turns off encryption. | |
570 | .TP 5 | |
571 | ($)\|= | |
572 | The line number of the addressed line is typed. | |
573 | `\fB.\fR' is unchanged by this command. | |
574 | .TP 5 | |
575 | !<shell command> | |
576 | The remainder of the line after the `!' is sent | |
577 | to | |
578 | .IR sh (1) | |
579 | to be interpreted as a command. | |
580 | .RB ` . ' | |
581 | is unchanged. | |
582 | .TP 5 | |
583 | .RB (\| . +1)\|<newline> | |
584 | An address alone on a line causes the addressed line to be printed. | |
585 | A blank line alone is equivalent to `.+1p'; it is useful | |
586 | for stepping through text. | |
587 | .PP | |
588 | If an interrupt signal (ASCII DEL)\| is sent, | |
589 | .I ed | |
590 | prints a `?' and returns to its command level. | |
591 | .PP | |
592 | Some size limitations: | |
593 | 512 characters per line, | |
594 | 256 characters per global command list, | |
595 | 64 characters per file name, | |
596 | and 128K characters in the temporary file. | |
597 | The limit on the number of lines depends on the amount of core: | |
598 | each line takes 1 word. | |
599 | .PP | |
600 | When reading a file, | |
601 | .I ed | |
602 | discards ASCII NUL characters | |
603 | and all characters after the last newline. | |
604 | It refuses to read files containing non-ASCII characters. | |
605 | .SH FILES | |
606 | /tmp/e* | |
607 | .br | |
608 | ed.hup: work is saved here if terminal hangs up | |
609 | .SH "SEE ALSO" | |
610 | B. W. Kernighan, | |
611 | .I | |
612 | A Tutorial Introduction to the ED Text Editor | |
613 | .br | |
614 | B. W. Kernighan, | |
615 | .I Advanced editing on UNIX | |
616 | .br | |
617 | sed(1), crypt(1) | |
618 | .SH DIAGNOSTICS | |
619 | `?name' for inaccessible file; | |
620 | `?' for | |
621 | errors in commands; | |
622 | `?TMP' for temporary file overflow. | |
623 | .PP | |
624 | To protect against throwing away valuable work, | |
625 | a | |
626 | .I q | |
627 | or | |
628 | .I e | |
629 | command is considered to be in error, unless a | |
630 | .I w | |
631 | has occurred since the last buffer change. | |
632 | A second | |
633 | .I q | |
634 | or | |
635 | .I e | |
636 | will be obeyed regardless. | |
637 | .SH BUGS | |
638 | The | |
639 | .I l | |
640 | command mishandles DEL. | |
641 | .br | |
642 | A | |
643 | .I ! | |
644 | command cannot be subject to a | |
645 | .I g | |
646 | command. | |
647 | .br | |
648 | Because 0 is an illegal address for a | |
649 | .I w | |
650 | command, it is not possible to | |
651 | create an empty file with | |
652 | .I ed. |