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