Commit | Line | Data |
---|---|---|
445c7738 KB |
1 | .\" Copyright (c) 1992 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Rodney Ruddock of the University of Guelph. | |
6 | .\" | |
7 | .\" %sccs.include.redist.roff% | |
8 | .\" | |
05ee7127 | 9 | .\" @(#)ed.1 5.9 (Berkeley) %G% |
445c7738 KB |
10 | .\" |
11 | .TH ED 1 "" | |
12 | .SH NAME | |
13 | ed \- line oriented text editor | |
14 | .SH SYNOPSIS | |
15 | .B ed | |
16 | [ | |
17 | .B \-p | |
18 | .I prompt-string | |
19 | ] [ | |
20 | .B \-s | |
21 | ] [ | |
22 | .B \-v | |
23 | ] [ | |
24 | .I filename | |
25 | ] | |
26 | .SH DESCRIPTION | |
27 | .I Ed | |
e692f66f | 28 | is a standard text editor. |
445c7738 KB |
29 | .PP |
30 | \fIEd\fR is a powerful line oriented editor. Although ex(1)/vi(1) have gained | |
31 | popularity, \fIed\fR still maintains advantages over them. Most notable points | |
32 | are the | |
33 | .I W | |
34 | command (see below) (which is not part of ex(1)/vi(1)\|), the | |
e692f66f KB |
35 | smaller executable size (you can often be editing before the others finish |
36 | loading), and the better response when editing from slow terminals or across | |
445c7738 KB |
37 | low baud data lines. \fIEd\fR continues to be used by many system utilities. |
38 | .SH OPTIONS | |
39 | .PP | |
40 | When a filename is present \fIed\fR starts by simulating an | |
41 | .I e | |
42 | command (see below) | |
43 | If no filename is present \fIed\fR | |
44 | starts with an empty buffer. | |
45 | The option | |
46 | .B \-p | |
47 | allows for the setting of a prompt string in | |
48 | .IR ed . | |
49 | The option | |
50 | .B \-s | |
51 | suppresses the printing | |
52 | of explanatory output | |
53 | (from the commands | |
54 | .IR e , | |
55 | .IR E , | |
56 | .IR r , | |
57 | .IR w , | |
58 | .I W | |
59 | and | |
60 | .IR wq ; | |
61 | see below) and should be used with a script. | |
62 | The | |
63 | .B \-v | |
64 | option will display a message of which mode (BSD or POSIX) | |
65 | .I ed | |
66 | as been set locally. This is useful for determining the described | |
67 | behavior below. | |
68 | .PP | |
69 | .I Ed | |
70 | performs all changes to a copy of the file which is contained in a \fBbuffer\fR. | |
71 | For the changes to have an effect one of the write commands ( | |
72 | .IR w , | |
73 | .IR W , | |
74 | .IR wq , | |
75 | or | |
76 | .IR Wq ) | |
77 | must be issued. | |
78 | .PP | |
79 | The contents of the | |
80 | .B buffer | |
81 | can changed by issuing commands that are lead | |
82 | by zero, one, or two addresses. All commands are alphabetically listed below | |
83 | with their parameter structures if applicable; trailing structures not | |
84 | described with commands are regarded as erroneous. Commands that | |
85 | accept zero addresses regard the presence of any address as an error. | |
86 | .PP | |
87 | .I Ed | |
88 | works in two modes: command, and input. The two modes are exclusive of | |
89 | each other. While in command mode | |
90 | .I ed | |
91 | accepts commands that display, modify, or give information about the | |
92 | .BR buffer . | |
93 | While in input mode | |
94 | .I ed | |
95 | accepts lines of text to be added to the | |
96 | .BR buffer . | |
97 | .PP | |
98 | Addressing in \fIed\fR specifies one or more lines contained in the | |
99 | .BR buffer . | |
100 | For commands that expect at least one address, and none are given, default | |
101 | addresses will be used. | |
102 | Using addresses in | |
103 | .I ed | |
104 | involves understanding that during the execution of most | |
105 | .I ed | |
106 | commands that a | |
107 | .I "current line" | |
108 | ( | |
109 | .BR current ) | |
110 | exists. | |
111 | .B Current | |
112 | (as a rule of thumb) is the location in the | |
113 | .B buffer | |
114 | that the last command issued affected; some | |
115 | commands do not affect | |
116 | .BR current . | |
117 | Each command description (below) describes | |
118 | its affects on | |
119 | .B current | |
120 | as the affect will vary depending under which compile option (BSD or POSIX) | |
121 | .I ed | |
122 | was compiled under. | |
123 | Addresses can be divided into three cases: one | |
124 | address (\fBsingle address\fR), two addresses (an \fBaddress pair\fR), | |
125 | and special address forms. | |
126 | ||
127 | For the first two cases | |
128 | an address is formed with the use of: | |
129 | .TP | |
130 | 1. | |
131 | A positive decimal integer (e.g. 123) indicating a line number in the buffer. | |
132 | Line number 1 is the first line in the buffer. | |
133 | .TP | |
134 | 2. | |
135 | The `.' character indicating the current line (\fBcurrent\fR). | |
136 | .TP | |
137 | 3. | |
138 | The `$' character which indicates the last line in the buffer. | |
139 | .TP | |
140 | 4. | |
141 | A regular expression (RE) enclosed with `/'s as delimiters (i.e. /RE/). | |
142 | This causes a forward search to the first occurrence of the specified RE. The | |
143 | address will then become this line. | |
144 | The character sequence \e/ escapes the forwardslash from being a | |
145 | delimiter. | |
146 | The search will wrap from the bottom of | |
147 | the buffer to the top of the buffer if need be. | |
148 | .I Ed | |
149 | RE's are, outside of this document, now refered to as | |
150 | .IR "basic regular expressions" . | |
151 | Basic regular expressions (BRE's), traditionally described in \fIed(1)\fR are | |
05ee7127 | 152 | now fully described in regex(7). BRE's are, for the most part, the same as |
445c7738 KB |
153 | the old RE's - the name has changed and the expressions extended to meet |
154 | POSIX 1003.2 specifications. (See the search command for more details.) | |
155 | .TP | |
156 | 5. | |
157 | A RE enclosed with `?'s as delimiters (i.e. ?RE?). | |
158 | This will cause a backward search to the first occurrence of the | |
159 | specified BRE. The address will then become this line. | |
160 | The character sequence \e? escapes the questionmark from being a | |
161 | delimiter. | |
162 | The search will wrap | |
163 | from the top of the buffer to the | |
164 | bottom of the buffer if need be. (See the search command for more details.) | |
165 | .TP | |
166 | 6. | |
167 | A line previously marked by the `k' command (see below). \fB`x\fR addresses | |
168 | the line marked by the single lower-case letter `\fBx\fR' (from the | |
169 | portable character set in the range a-z). | |
170 | .TP | |
171 | 7. | |
172 | An address of the form 1-6 followed by a `+' followed by an integer number, | |
173 | .BR n , | |
174 | specifies the line to be addressed is | |
175 | .B n | |
176 | lines after the address of the form | |
177 | 1-6. | |
178 | If the address starts with a `+' then by default the addressed line is taken | |
179 | with respect to | |
180 | .B current | |
181 | (equivalent to `.'\|; form 2). | |
182 | If no integer number is given then 1 is added to the address. | |
183 | Hence, if | |
184 | more than one `+' is given in a sequence, with no integer number following, | |
185 | 1 is added to the address for each `+'. Therefore, +++ is eqivalent to +3, | |
186 | but +++1 is equivalent to +1. | |
187 | .TP | |
188 | 8. | |
189 | An address of the form 1-6 followed by a `\-' followed by an integer number, | |
190 | .BR n , | |
191 | specifies the line to be addressed is | |
192 | .B n | |
193 | lines before the address of the form | |
194 | 1-6. | |
195 | If the address starts with a `\-' then by default the | |
196 | addressed line is taken | |
197 | with respect to | |
198 | .B current | |
199 | (`.'\|; form 1). | |
200 | If no integer number is given then 1 is subtracted from the address. | |
201 | Hence, if | |
202 | more than one `\-' is given in a sequence, with no integer number following, | |
203 | 1 is subtracted from the address for each `\-'. Therefore, \-\-\- | |
204 | is eqivalent to \-3, | |
205 | but \-\-\-1 is equivalent to \-1. | |
206 | For backward compatibility `^' is the equivalent to `\-'. | |
207 | .TP | |
208 | 9. | |
209 | A `,' (comma) may be used to separate two addresses of the form 1-8 to | |
210 | create an \fBaddress pair\fR. | |
211 | The first address must occur no later in | |
212 | the buffer than the second address to be legal. | |
213 | .TP | |
214 | 10. | |
215 | A `;' (semicolon) may be used to separate two addresses of the form 1-8 to | |
216 | create an \fBaddress pair\fR. | |
217 | With this form the second address is evaluated with respect to | |
218 | and after the first address has been evaluated. This is useful when | |
219 | addresses of the forms 2-8 are used. | |
220 | The first address must occur no later in | |
221 | the buffer than the second address to be legal. | |
222 | .TP | |
223 | NOTE: | |
224 | Addresses of the forms 7 and 8 cannot be followed by addresses | |
225 | of forms 2-6; it is an error. | |
226 | .PP | |
227 | The following are special address forms that cannot be combined | |
228 | with any of the address forms listed above. | |
229 | A `,' by itself represents the address pair `1,$'. | |
230 | Likewise `%' by itself represents the address pair `1,$'. | |
231 | A `;' by itself represents the address pair `.,$'. | |
232 | .PP | |
233 | The \fIed\fR commands listed below default to the addresses prefixing the | |
234 | commands. Commands without default addresses accept zero addresses. | |
235 | The parentheses with the default addresses are not part of | |
236 | the address; they are used to show that the addresses are | |
237 | default. | |
238 | .PP | |
239 | Generally only one command appears on a line at a time. | |
240 | However, many of the commands may be suffixed by `l', `n', | |
241 | or `p', in which case | |
242 | the current line is printed | |
243 | in the manner discussed below. | |
244 | These suffixes may be combined in any order. | |
245 | .TP 5 | |
246 | .RB (\|.\|)\|a | |
247 | .br | |
248 | .ns | |
249 | .TP 5 | |
250 | <text> | |
251 | .br | |
252 | .ns | |
253 | .TP 5 | |
254 | .B . | |
255 | .br | |
256 | Append text after the addressed line. A `.' in the first column | |
257 | followed immediately by a <newline> places | |
258 | .I ed | |
259 | back in command mode - the `.' is not included in the text. Line 0 | |
260 | is legal for this command; text will be placed at the top of the buffer. | |
261 | .B Current | |
262 | is the last line appended (or the addressed line if no text given). | |
263 | .TP 5 | |
264 | .RB (\|.\|,\|.\|)\|c | |
265 | .br | |
266 | .ns | |
267 | .TP 5 | |
268 | <text> | |
269 | .br | |
270 | .ns | |
271 | .TP 5 | |
272 | .B . | |
273 | .br | |
274 | Change text on the addressed line(s). The addressed lines are deleted | |
275 | before | |
276 | .I | |
277 | ed | |
278 | is placed in input mode. A `.' in the first column | |
279 | followed immediately by a <newline> places | |
280 | .I ed | |
281 | back in command mode - the `.' is not included in the text. | |
282 | .B Current | |
283 | is the new last line appended (or if no text is given the line after | |
284 | the addressed line deleted). | |
285 | .TP 5 | |
286 | .RB (\|.\|,\|.\|)\|d | |
287 | Delete the addressed line(s) from the buffer. Deleted lines may be | |
288 | recovered with the undo command (\fIu\fR; see below). | |
289 | .B | |
290 | Current | |
291 | is the line after the last addressed line deleted. | |
292 | .TP 5 | |
293 | e [filename] | |
294 | Edit the new file `filename'. The | |
295 | .B buffer | |
296 | is cleared and the new file is placed in the | |
297 | .BR buffer . | |
298 | If the | |
299 | .B buffer | |
300 | has been modified since the last write command | |
301 | .I ed | |
302 | will issue a warning (`?'); a second issuing of | |
303 | the command will be obeyed regardless. | |
304 | The number of characters read is printed (unless -s is specified | |
305 | at startup). If `filename' is missing, the remembered | |
306 | name is used. | |
307 | If `filename' is lead by ! then it shall be interpreted as a shell | |
2d5f5b81 KB |
308 | command to be executed, from which the standard output will be |
309 | placed into the buffer; `filename' will be non-remembered. | |
445c7738 KB |
310 | Undo will not restore the |
311 | .B buffer | |
312 | to its state before the edit command. | |
313 | .B Current | |
314 | is the last line in the | |
315 | .B buffer | |
316 | (`$'). | |
317 | .TP 5 | |
318 | E [filename] | |
319 | .I E | |
320 | works the same as | |
321 | .I e | |
322 | except if the buffer has been modified no warning is issued. | |
323 | .TP 5 | |
324 | f [filename] | |
325 | Print the | |
326 | .BR "remembered filename" . | |
327 | If `filename' is specified the | |
328 | .B "remembered filename" | |
329 | will be set to `filename'. | |
330 | If `filename' is lead by ! then it shall be interpreted as a shell | |
2d5f5b81 KB |
331 | command to be executed, from which the standard output will be used as |
332 | the new remembered filename. | |
445c7738 KB |
333 | .B Current |
334 | is unchanged. | |
335 | .TP 5 | |
336 | (1,$)\|g/regular expression/command list | |
337 | The global command first marks all lines matching | |
338 | the regular expression. | |
339 | For each matching line, the | |
340 | command list is executed. At the start of each command list execution, | |
341 | \fBcurrent\fR is set to equal that line; \fBcurrent\fR may change | |
342 | as each command in the command list is executed for that line. | |
343 | The first command of the command list begins on the same line as | |
344 | the global command. | |
345 | Generally, in the command list one command occupies a line. Thus to | |
346 | have multiple commands in the command list it is necessary to escape the | |
347 | <newline> at the end of each line so that the global command does not | |
348 | interpret it as an indication that the command list entry has ended. | |
71fc9f52 | 349 | The <newline> is escaped by proceeding it with a backslash (`\e'). |
445c7738 | 350 | Similarly with the commands that set \fIed\fR into input mode the <newlines> |
e692f66f KB |
351 | of the entered text need to be escaped. If the `.' used to end input mode |
352 | is the last line of the command list the <newline> following the `.' need | |
353 | not be escaped, or the `.' may be omitted entirely. | |
445c7738 KB |
354 | Commands in the command list can affect any line in the buffer. |
355 | For the behaviour of each \fIed\fR command within a command list refer to the | |
71fc9f52 | 356 | information on the individual command, particularly \fIs\fR and \fI!\fR. |
445c7738 KB |
357 | The commands |
358 | .IR g , | |
359 | .IR G , | |
360 | .IR v , | |
361 | .IR V , | |
362 | and \fI!\fR | |
363 | are permitted in the command list, but should be used with caution. | |
364 | The command list defaults to | |
365 | .I p | |
366 | if left empty (i.e. g/RE/p). | |
367 | For the regular expression the delimiters can be any characters except | |
368 | for <space> and <newline>; delimiters within a regular expression can | |
369 | be escaped with a backslash preceeding it. | |
370 | .TP 5 | |
371 | (1,$)\|G/regular expression/ | |
372 | .br | |
373 | The interactive global command works similar to \fIg\fR. The first step | |
374 | is to mark every line which matches the given regular expression. | |
375 | For every line matched it will print this line, set \fBcurrent\fR | |
376 | to this line, and accept one command (not including \fIa\fR, \fIc\fR, \fIi\fR, \fIg\fR, \fIG\fR, \fIv\fR, and \fIV\fR) | |
377 | for execution. | |
378 | The command can affect any line in the buffer. `%' by itself executes | |
379 | the last non-null command. | |
380 | A return by itself will act as a null command. \fBCurrent\fR | |
381 | will be set to the last line affected by the last successful command | |
382 | input. If no match or an input command error occurs \fBcurrent\fR | |
383 | will be set to the last line searched by \fIG\fR. \fIG\fR can be prematurely | |
384 | ended by `ctrl-C' (SIGINT). | |
71fc9f52 KB |
385 | For the behaviour of each \fIed\fR command within a command list refer to the |
386 | information on the individual command, particularly \fIs\fR and \fI!\fR. | |
445c7738 KB |
387 | |
388 | .TP 5 | |
389 | h | |
390 | .br | |
391 | The help command displays a message explaining the most recent command | |
392 | error (indicated by `?'). \fBCurrent\fR is unchanged. | |
393 | .TP 5 | |
394 | H | |
395 | .br | |
396 | This toggles on or off the automatic display of messages explaining | |
397 | the most recent command error in place of `?'. \fBCurrent\fR is | |
398 | unchanged. | |
399 | .TP 5 | |
400 | .RB (\|.\|)\|i | |
401 | .TP 5 | |
402 | <text> | |
403 | .br | |
404 | .TP 5 | |
405 | .B . | |
406 | .br | |
407 | The insert command places | |
408 | .I ed | |
409 | in input mode with the text being placed before the | |
410 | addressed line. Line 0 is invalid for this command. | |
411 | A `.' in the first column | |
412 | followed immediately by a return places | |
413 | .I ed | |
414 | back in command mode - the `.' is not included in the text. | |
415 | .B Current | |
416 | is the last line inserted. If no text is inserted then | |
417 | .B current | |
418 | is the addressed when | |
419 | .I ed | |
420 | is compiled for POSIX; compiled for BSD, | |
421 | .B current | |
422 | is the addressed line -1. | |
423 | .TP 5 | |
424 | .RB (\|.\|,\|.+1)\|j | |
425 | The join command joins the addressed lines together to make one | |
426 | line. If no addresses are specified | |
427 | .B current | |
428 | and | |
429 | .BR current +1 | |
430 | lines are joined. | |
431 | If one address only is given then | |
432 | no join is performed. | |
433 | .B Current | |
434 | becomes that line if | |
435 | .I ed | |
436 | has been compiled under the BSD option; if compiled under the POSIX | |
437 | option | |
438 | .B current | |
439 | is unchanged. | |
440 | .TP 5 | |
441 | ( \fB. \fR)\|k\fBx\fR | |
442 | The mark command marks the addressed line with label | |
443 | .BR x , | |
444 | where | |
445 | .B x | |
446 | is a lowercase letter from the portable character set (a-z). | |
447 | The address form \fB`x\fR will refer to | |
448 | this line (address form 6 above). | |
449 | .B Current | |
450 | is unchanged. | |
451 | .TP 5 | |
452 | .RB (\|.\|,\|.\|)\|l | |
453 | The list command | |
454 | prints the addressed lines in an unambiguous way: | |
455 | non-graphic characters are | |
456 | printed in three-digit octal preceded by a \e | |
457 | unless they are one of the following in which case they will be printed | |
458 | as indicated in the brackets: | |
459 | backslash (`\e\\'), | |
460 | horizontal tab (\et), form feed (\ef). | |
461 | return (\er), vertical tab (\ev), and backspace (\eb). | |
462 | Long lines will be broken base on the type of terminal currently in | |
463 | use. | |
464 | .B Current | |
465 | is set to the last line printed. | |
466 | The | |
467 | .I l | |
468 | command may be placed on the same line after any | |
469 | command except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR). | |
470 | .TP 5 | |
471 | .RB (\|.\|,\|.\|)\|m\fBa\fR | |
472 | The move command moves the addressed lines in the buffer | |
473 | to after the address | |
474 | .BR a . | |
05ee7127 | 475 | Line 0 is valid as the address \fBa\fR for this command. |
445c7738 KB |
476 | .B Current |
477 | is the location in the | |
478 | .B buffer | |
479 | of the last line moved. | |
480 | .TP 5 | |
481 | .RB (\|.\|,\|.\|)\|n | |
482 | The number command prints the addressed lines preceding the text with the line number. | |
483 | The | |
484 | .I n | |
485 | command | |
486 | may | |
487 | be placed on the same line after any command | |
488 | except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR). | |
489 | .B Current | |
490 | is the last line printed. | |
491 | .TP 5 | |
492 | .RB (\|.\|,\|.\|)\|p | |
493 | The print command prints the addressed lines. | |
494 | The | |
495 | .I p | |
496 | command | |
497 | may | |
498 | be placed on the same line after any command | |
499 | except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR). | |
500 | .B Current | |
501 | is the last line printed. | |
502 | .TP | |
503 | .RB (\|.\|,\|.\|)\|P | |
504 | This command is a synonym for | |
505 | .I p | |
506 | if | |
507 | .I ed | |
508 | has been compiled under the BSD option. If | |
509 | .I ed | |
510 | has been compiled under the POSIX option then the prompt is toggled on or off. | |
511 | .B Current | |
512 | is unchanged when compiled under the POSIX option. | |
513 | The default prompt is "*" if not specified with the \-p option at startup. | |
514 | The prompt is initially off unless the \-p option is specified. | |
515 | .TP 5 | |
516 | q | |
517 | The quit command causes | |
518 | .I ed | |
71fc9f52 | 519 | to exit. If the entire |
445c7738 | 520 | .B buffer |
71fc9f52 | 521 | (1,$) has not been written since the last modification |
445c7738 KB |
522 | .I ed |
523 | will | |
524 | issue a warning once (`?'); a second issuing of the command will be obeyed | |
525 | regardless. | |
526 | .TP 5 | |
527 | Q | |
528 | .I Q | |
529 | works the same as | |
530 | .I q | |
531 | except if the buffer has been modified no warning is issued. | |
532 | .TP 5 | |
533 | ($)\|r [filename] | |
534 | The read command reads in the file `filename' after the | |
535 | addressed line. If no `filename' is specified then the | |
536 | .B "remembered filename" | |
537 | is used. Address 0 is valid for this command. | |
538 | If read is successful then the number of characters | |
539 | read is printed (unless the -s option is specified). | |
540 | If `filename' is lead by ! then it shall be interpreted as a shell | |
2d5f5b81 KB |
541 | command to be executed, from which the standard output will be |
542 | placed in the buffer; `filename' will be non-remembered. | |
445c7738 KB |
543 | .B Current |
544 | is the last line read. | |
545 | .TP 5 | |
546 | (\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/\fBreplacement\fR/\fBflags\fR | |
547 | .br | |
548 | The substitute command searches for the regular expression in the | |
549 | addressed lines. | |
550 | On each line in which a match is found, | |
551 | matched strings are replaced by the \fBreplacement\fR as specified | |
552 | by the \fBflags\fR (see below). | |
553 | If no \fBflags\fR appear, by default only the first occurrence | |
554 | of the matched string in each line is replaced. | |
555 | It is an error if no matches to the RE occur. | |
556 | .IP | |
557 | The delimiters may be any character except <space> or <newline>. | |
558 | The delimiter lead by a \e will escape it to be a literal | |
559 | in the RE or | |
560 | .BR replacement . | |
561 | .IP | |
562 | An ampersand, `&', appearing in the replacement | |
563 | will equal the string matching the RE. | |
564 | The `&'s special meaning is supressable by leading | |
565 | it with a `\e'. | |
566 | When `%' is the only replacement character in | |
567 | .B replacement | |
568 | the most recent | |
569 | replacement is used. | |
570 | The `%'s special meaning is supressable by leading | |
571 | it with a `\e'. | |
572 | .IP | |
573 | The characters `\fB\en\fR' (where \fBn\fR is a digit 1-9) is | |
574 | replaced by the text matching the RE subexpression | |
575 | .B n | |
576 | (known as backreferencing). | |
577 | .I S | |
578 | may be used to break lines by including a <newline> in | |
579 | .B replacement | |
580 | preceeded by a backslash (`\e') to escape it. | |
581 | .B Replacement | |
582 | can continue on the next line and can include another escaped <newline>. | |
583 | .IP | |
584 | The following extention should not be included in portable scripts. | |
71fc9f52 KB |
585 | When spliting lines using \fIs\fR within the global commands (\fIg\fR, |
586 | \fIG\fR, \fIv\fR, or \fIV\fR) the <newline> in the replacement string | |
445c7738 | 587 | must be escaped by preceding it with `\e\e\e' (three adjacent `\e'\|s \- |
71fc9f52 KB |
588 | the first `\e' escapes the second `\e' so that it is passed to \fIs\fR |
589 | to escape the <newline> passed by the global command; the third `\e' | |
590 | is to escape the <newline> so that the global command list continues). | |
591 | [N.B. Other \fIed\fR's do not allow line | |
2d5f5b81 | 592 | splitting within the global commands]. |
445c7738 KB |
593 | .IP |
594 | The \fBflags\fR may be any combination of: | |
595 | .RS | |
596 | .IP \fIcount\fR | |
597 | in each addressed line replace the \fIcount\fR\-th matching occurrence. | |
598 | .IP g | |
599 | in each addressed line replace all matching occurrences. When \fIcount\fR and | |
600 | g are specified together inclusively replace in each addressed line | |
601 | all matches from the \fIcount\fR\-th match to the end of line. | |
602 | .IP l | |
603 | write the line after replacement in the manner specified by the \fIl\fR | |
604 | command. | |
605 | .IP n | |
606 | write the line after replacement in the manner specified by the \fIn\fR | |
607 | command. | |
608 | .IP p | |
609 | write the line after replacement in the manner specified by the \fIp\fR | |
610 | command. | |
611 | .RE | |
612 | .IP | |
613 | The following special form | |
614 | should not be included in portable scripts. | |
615 | This form is maintained for backward compatibility and | |
616 | is extended to dovetail into the above forms of | |
617 | .BR s . | |
618 | .I S | |
619 | followed by | |
620 | .I no | |
621 | delimiters | |
622 | repeats the most recent substitute command | |
623 | on the addressed lines. | |
624 | .I S | |
625 | may be suffixed with the letters | |
626 | .BR r " (use the most recent RE rather than the last RE used with \fIs\fR)," | |
627 | .B p | |
628 | (complement the setting of the | |
629 | any print command (l, n, p) | |
630 | suffix from the previous substitution), | |
631 | .B g | |
632 | (complement the setting of the | |
633 | .I g | |
634 | suffix) or | |
635 | .B N | |
636 | (negate the previous \fIcount\fR flag). | |
637 | These modifying letters may be combined in any order | |
638 | (N.B. multiple use of the modifying letters may cause them | |
639 | to be interpreted as delimiters). | |
640 | .IP | |
641 | .B Current | |
642 | is set to the last line search (BSD) or where the last replacement | |
643 | occurred (POSIX). | |
644 | .TP 5 | |
645 | .RB (\|.\|,\|.\|)\|t\|\fBa\fR | |
646 | The transcribe command copies the addressed lines in | |
647 | the | |
648 | .B buffer | |
649 | to after the address | |
650 | .BR a . | |
05ee7127 | 651 | Address 0 is valid as the address \fBa\fR for this command. |
445c7738 KB |
652 | .B Current |
653 | is the last line transcribed. | |
654 | .TP 5 | |
655 | .RB (\|.\|,\|.\|)\|u | |
656 | The undo command nullifies the most recent | |
657 | .B buffer | |
658 | modifying command. | |
659 | Buffer modifying commands undo works on are | |
660 | .IR a , | |
661 | .IR c , | |
662 | .IR d , | |
663 | .IR g , | |
664 | .IR G , | |
665 | .IR i , | |
666 | .IR j , | |
667 | .IR m , | |
668 | .IR r , | |
669 | .IR s , | |
670 | .IR t , | |
671 | .IR u , | |
672 | .IR v , | |
673 | and | |
674 | .I V. | |
675 | Marks set by the \fIk\fR command will also be restored. | |
676 | All commands (including nested \fIg\fR, \fIG\fR, \fIv\fR, and | |
677 | \fIV\fR commands within the \fIg\fR or \fIv\fR) | |
678 | that undo works on are treated as a single buffer modification. | |
679 | \fBCurrent\fR is set to the line it addressed before the last | |
680 | buffer modification. | |
681 | .TP 5 | |
682 | (1, $)\|v/regular expression/command list | |
683 | The global non-matching command performs as the | |
684 | .I g | |
685 | command does except that the command list is executed for every line | |
686 | that does not match the RE. | |
687 | .TP 5 | |
688 | (1, $)\|V/regular expression/ | |
689 | The interactive global non-matching command is the same as the | |
690 | .I G | |
691 | except that one command will be accepted as input | |
692 | with \fBcurrent\fR initially set to every line | |
693 | that does not match the RE. | |
694 | .TP 5 | |
695 | (1, $)\|w [filename] | |
696 | .br | |
697 | The write command writes the addressed lines to the file `filename'. | |
698 | If no `filename' is specified then the | |
699 | .B "remembered filename" | |
700 | is used. If no addresses are specified the whole | |
701 | .B buffer | |
702 | is written. | |
703 | If the command is successful, the number of characters written is | |
704 | printed (unless the -s option is specified). | |
705 | If `filename' is lead by ! then it shall be interpreted as a shell | |
2d5f5b81 KB |
706 | command to be executed which will accept on its standard input |
707 | the section of the buffer specified for writting. | |
445c7738 KB |
708 | \fBCurrent\fR is unchanged. |
709 | .TP | |
710 | (1, $)\|W [filename] | |
711 | .I W | |
712 | works as the | |
713 | .I w | |
714 | command does except the addressed contents of the | |
715 | .B buffer | |
716 | are appended to `filename' (or the | |
71fc9f52 | 717 | .B "remembered filename" |
2d5f5b81 KB |
718 | if `filename' is not specified). If `filename' is lead by ! then |
719 | .I W | |
720 | will act exactly as the | |
721 | .I w | |
722 | command. | |
445c7738 KB |
723 | \fBCurrent\fR is unchanged. |
724 | .TP 5 | |
725 | (1, $)\|wq [filename] | |
726 | .I wq | |
727 | works as the | |
728 | .I w | |
729 | command does with the addition that | |
730 | .I ed | |
731 | exits immediately after the write is complete. | |
732 | \fBCurrent\fR is unchanged. | |
733 | .TP 5 | |
734 | (1,$)\|Wq [filename] | |
735 | .I Wq | |
736 | works as the | |
737 | .I W | |
738 | command does with the addition that | |
739 | .I ed | |
71fc9f52 | 740 | exits immediately after the appended write is complete. |
445c7738 KB |
741 | \fBCurrent\fR is unchanged. |
742 | .TP 5 | |
743 | .RB (\|.\|+1)\|z\ \ \ \ or, | |
744 | .br | |
745 | .TP 5 | |
746 | .RB (\|.\|+1)\|z\fBn\fR | |
747 | Scroll through the | |
748 | .BR buffer . | |
749 | Starting from the addressed line (or | |
750 | .BR current +1) | |
751 | print the next 22 (by default or | |
752 | .BR n ) | |
753 | lines. The | |
754 | .B n | |
755 | is a sticky value; it becomes the default number of lines printed | |
756 | for successive scrolls. | |
757 | .B Current | |
758 | is the last line printed. | |
759 | .TP 5 | |
760 | ($)\|= | |
761 | Print the number of lines in the | |
762 | .BR buffer . | |
763 | If an address is provided (in the forms 1-8 above) then the line number | |
764 | for that line will be printed. | |
765 | \fBCurrent\fR is unchanged. | |
766 | .TP 5 | |
767 | !<shell command> | |
768 | The command after the | |
769 | .I ! | |
770 | is executed by \fIsh(1)\fR and the results are printed. A `!' is | |
771 | printed in the first column when execution has completed (unless the -s | |
772 | option has been specified). | |
71fc9f52 KB |
773 | A `!' immediately after \fI!\fR repeats the last shell command. |
774 | An unescaped `%' represents the remembered filename. | |
775 | Commands to \fIsh(1)\fR can have several lines by escaping the <newline> | |
776 | with a `\e' immediately before it. The line continuation character | |
777 | for \fIsh(1)\fR, `\e', can be included on a line provided that it | |
778 | is escaped by a `\e' immediately before so that \fIed\fR passes it | |
779 | literally to \fIsh(1)\fR: `\e\e'. It is implicit that for the command | |
780 | line that the \fIsh(1)\fR line continuation character is on that the | |
781 | <newline> will be escaped (e.g. `\e\e\e<newline>'). | |
782 | This behavior can be used within global command lists. However, an | |
783 | additional `\e' must be added so that the \fI!\fR command continuor is | |
784 | passed to \fI!\fR - it must occur immediately before the global | |
785 | command's continuor. Therefore, | |
786 | the \fI!\fR command continuation sequence in a global command list | |
787 | will appear as `\e\e\e' (explanation as with \fIsfR). The line continuation | |
788 | character for \fIsh(1)\fR needs no additional escaping (since it it | |
789 | not dependant on <newline> being adjacent) - hence, the | |
790 | sequence in a global command list with a line continuation will appear | |
791 | as `\e\e\e\e\e<newline>'. | |
792 | ||
445c7738 KB |
793 | \fBCurrent\fR is unchanged. |
794 | .TP 5 | |
795 | /regular expression/\|\|\|\|\|or, | |
796 | .br | |
797 | .TP 5 | |
798 | ?regular expression? | |
799 | .br | |
800 | The search command searches forward, `/', (or backward, `?') through the | |
801 | .B buffer | |
802 | attempting to find | |
803 | a line that matches the RE. The search will wrap to the top (or bottom) | |
804 | of the | |
805 | .B buffer | |
806 | if necessary. Search returns the line number that the match occurs on - | |
807 | combined with the null command (see below) this causes the line to be printed. | |
808 | .B Current | |
809 | is the matching line. | |
810 | .TP 5 | |
811 | .RB (\|.+1,\|.+1)\|<newline> | |
812 | .br | |
813 | The null command is equivalent to asking for the line | |
814 | .BR current +1 | |
815 | to be printed according to the | |
816 | .I p | |
817 | command. This is a useful command to quickly print the next couple of | |
818 | lines. If more than a couple of lines are needed the | |
819 | .I z | |
820 | command (see above) is much better to use. | |
821 | \fBCurrent\fR is the last line printed. | |
822 | ||
823 | .SH OTHER | |
824 | .PP | |
825 | If an interrupt signal (SIGINT)\| is sent, | |
826 | .I ed | |
827 | prints `?' | |
828 | and returns to command mode. | |
829 | .PP | |
830 | BSD command pairs (pp, ll, etc.) are permitted. Additionally any single | |
831 | print command may follow any of the non-I/O commands (I/O commands: | |
832 | e, E, f, r, w, W, wq, and !). This will cause the current line to be | |
833 | printed in the specified manner after the command has completed. | |
834 | .PP | |
835 | Previous limitations on the number of characters per line and per command | |
836 | list have been lifted; there is now no maximum. | |
837 | File name and path length is restricted to the maximum length that | |
838 | the current file system supports. | |
839 | The | |
840 | .I undo | |
841 | command now restores marks to affected lines. | |
842 | The temporary buffer method will vary dependent on the method selected at | |
843 | compile. Two methods work with a temporary file (stdio and db), while the | |
844 | third uses memory. | |
845 | The limit on the number of lines depends on the amount of memory. | |
846 | .SH FILES | |
2d5f5b81 KB |
847 | /tmp/_bsd44_ed* |
848 | .br | |
445c7738 KB |
849 | .XP |
850 | ed.hup: the buffer is written to this file in the current | |
2d5f5b81 KB |
851 | directory if possible and in the HOME directory is not |
852 | (if the signal SIGHUP (hangup) is received). | |
445c7738 KB |
853 | .SH "SEE ALSO" |
854 | B. W. Kernighan, | |
855 | .I | |
856 | A Tutorial Introduction to the ED Text Editor | |
857 | .br | |
858 | B. W. Kernighan, | |
859 | .I | |
860 | Advanced editing on UNIX | |
861 | .br | |
05ee7127 | 862 | ex(1), learn(1), regex(3), regex(7), sed(1), vi(1), POSIX 1003.2 (4.20) |
445c7738 KB |
863 | .SH "AUTHOR" |
864 | Rodney Ruddock | |
865 | .SH DIAGNOSTICS | |
866 | `?name' for a file that is either inaccessible, does not exist, or is | |
867 | a directory. `?' | |
868 | for all other errors unless the help messages have been toggled on (with | |
869 | the H command) in which case a descriptive message will be printed. | |
870 | .PP | |
2d5f5b81 KB |
871 | EOF is treated as a newline during input so that characters after the last <newline> |
872 | are included into the \fBbuffer\fR; the message "<newline> added at | |
873 | end of line" is printed. | |
445c7738 KB |
874 | .PP |
875 | .I Ed | |
2d5f5b81 KB |
876 | Returns an exit status of 0 on successful completion. A value >0 is returned |
877 | to indicate an \fIed\fR error: 1 for a command line error, 2 for HUP | |
878 | signal received, 4 for an \fIed\fR command error; these error values | |
879 | will be or'd together when appropriate. | |
445c7738 KB |
880 | .SH NOTES |
881 | .PP | |
882 | Regular expressions are now described on regex(7). | |
883 | .I Ed | |
884 | follows basic regular expressions (BRE's) as described on regex(7). | |
885 | BRE's, for the most part, are the same as previous | |
886 | .I ed | |
2d5f5b81 | 887 | RE's. The changes to the RE's are extensions for internationalization |
445c7738 KB |
888 | under POSIX 1003.2. Old scripts with RE's should work without |
889 | modification. | |
890 | .PP | |
05ee7127 KB |
891 | Regular expression logic is very tight. If you believe a command with a |
892 | regular expression in it has performed erroneously then a close reading | |
893 | of regex(7) is likely required. | |
894 | .PP | |
895 | Address `0' is legal only for those commands which explicitly state that | |
896 | it may be used; its use is illegal for all other commands. | |
897 | .PP | |
445c7738 KB |
898 | The special form of substitute has been maintained for backward |
899 | compatability and should not be used in scripts if they are to | |
900 | portable. | |
901 | .PP | |
902 | Help messages may appear ambiguous to beginners - particularly when BRE's | |
903 | form part of the command. | |
904 | .PP | |
905 | For backward compatability, when more addresses are provided | |
906 | than required by a command the one or two addresses closest to the | |
907 | command are used (depending on how may addresses the command accepts). | |
908 | Portable scripts should not rely on this feature. | |
909 | .PP | |
910 | For backward compatibility the option `-' is | |
911 | equivalent to the `-s' option at the startup of | |
912 | .IR ed . |