|
|
1.1 ! root 1: .TH ED 1 ! 2: .CT 1 editor ! 3: .ds . (\|\f5.\fP\|) ! 4: .ds .. (\|\f5.,.\fP\|) ! 5: .ds 1$ (\|\f51,$\fP\|) ! 6: .SH NAME ! 7: ed, e \- text editor ! 8: .SH SYNOPSIS ! 9: .B ed ! 10: [ ! 11: .B - ! 12: ] ! 13: [ ! 14: .B -o ! 15: ] ! 16: [ ! 17: .I file ! 18: ] ! 19: .SH DESCRIPTION ! 20: .I Ed ! 21: is the standard text editor; ! 22: .I e ! 23: is another name for it. ! 24: .PP ! 25: If a ! 26: .I file ! 27: argument is given, ! 28: .I ed ! 29: simulates an ! 30: .L e ! 31: command (see below) on that file: ! 32: it is read into ! 33: .I ed's ! 34: buffer so that it can be edited. ! 35: The options are ! 36: .TP ! 37: .B - ! 38: Suppress the printing ! 39: of character counts by ! 40: .LR e , ! 41: .LR r , ! 42: and ! 43: .L w ! 44: commands and of the confirming ! 45: .L ! ! 46: by ! 47: .L ! ! 48: commands. ! 49: .TP ! 50: .B -o ! 51: (for output piping) ! 52: Place on the standard error file all output except writing by ! 53: .L w ! 54: commands. ! 55: If no ! 56: .I file ! 57: is given, make ! 58: .F /dev/stdout ! 59: the remembered file; see the ! 60: .L e ! 61: command below. ! 62: .PP ! 63: .I Ed ! 64: operates on a `buffer', a copy of the file it is editing; ! 65: changes made ! 66: in the buffer have no effect on the file until a ! 67: .L w ! 68: (write) ! 69: command is given. ! 70: The copy of the text being edited resides ! 71: in a temporary file called the ! 72: .IR buffer . ! 73: .PP ! 74: Commands to ! 75: .I ed ! 76: have a simple and regular structure: zero or ! 77: more ! 78: .I addresses ! 79: followed by a single character ! 80: .I command, ! 81: possibly ! 82: followed by parameters to the command. ! 83: These addresses specify one or more lines in the buffer. ! 84: Missing addresses are supplied by default. ! 85: .PP ! 86: In general, only one command may appear on a line. ! 87: Certain commands allow the ! 88: addition of text to the buffer. ! 89: While ! 90: .I ed ! 91: is accepting text, it is said ! 92: to be in ! 93: .I "input mode." ! 94: In this mode, no commands are recognized; ! 95: all input is merely collected. ! 96: Input mode is left by typing a period ! 97: .L . ! 98: alone at the ! 99: beginning of a line. ! 100: .PP ! 101: .I Ed ! 102: supports a limited form of ! 103: .I "regular expression" ! 104: notation. ! 105: A regular expression specifies ! 106: a set of strings of characters. ! 107: A member of this set of strings is said to be ! 108: .I matched ! 109: by the regular expression. ! 110: In the following specification for regular expressions ! 111: the word `character' means any character but newline. ! 112: .IP 1. ! 113: Any character except a special character ! 114: matches itself. ! 115: Special characters are ! 116: the regular expression delimiter plus ! 117: .L \e[. ! 118: and sometimes ! 119: .LR ^*$ . ! 120: .IP 2. ! 121: A ! 122: .B . ! 123: matches any character. ! 124: .IP 3. ! 125: A ! 126: .L \e ! 127: followed by any character except a digit, ! 128: .LR ( , ! 129: or ! 130: .L ) ! 131: matches that character. ! 132: .IP 4. ! 133: A nonempty string ! 134: .I s ! 135: bracketed ! 136: .BI [ \|s\| ] ! 137: (or ! 138: .BI [^ s\| ]) ! 139: matches any character in (or not in) ! 140: .I s. ! 141: In ! 142: .I s, ! 143: .L \e ! 144: has no special meaning, and ! 145: .L ] ! 146: may only appear as ! 147: the first letter. ! 148: A substring ! 149: .IB a - b , ! 150: with ! 151: .I a ! 152: and ! 153: .I b ! 154: in ascending ! 155: .SM ASCII ! 156: order, stands for the inclusive ! 157: range of ! 158: .SM ASCII ! 159: characters. ! 160: .IP 5. ! 161: A regular expression of form 1-4 followed by ! 162: .L * ! 163: matches a sequence of ! 164: 0 or more matches of the regular expression. ! 165: .IP 6. ! 166: A regular expression, ! 167: .I x, ! 168: of form 1-8, bracketed ! 169: .BI \e( \|x\| \e) ! 170: matches what ! 171: .I x ! 172: matches. ! 173: .IP 7. ! 174: A ! 175: .L \e ! 176: followed by a digit ! 177: .I n ! 178: matches a copy of the string that the ! 179: bracketed regular expression beginning with the ! 180: .IR n th ! 181: .L \e( ! 182: matched. ! 183: .IP 8. ! 184: A regular expression of form 1-8, ! 185: .I x, ! 186: followed by a regular expression of form 1-7, ! 187: .I y ! 188: matches a match for ! 189: .I x ! 190: followed by a match for ! 191: .I y, ! 192: with the ! 193: .I x ! 194: match being as long as possible while still permitting a ! 195: .I y ! 196: match. ! 197: .IP 9. ! 198: A regular expression of form 1-8, or a null string, preceded by ! 199: .L ^ ! 200: (and/or followed by ! 201: .LR $ ), ! 202: is constrained to matches that ! 203: begin at the left (and/or end at the right) end of a line. ! 204: .IP 10. ! 205: A regular expression of form 1-9 picks out the ! 206: longest among the leftmost matches in a line. ! 207: .IP 11. ! 208: An empty regular expression stands for a copy of the ! 209: last regular expression encountered. ! 210: .PP ! 211: Regular expressions are used in addresses to specify ! 212: lines and in one command ! 213: (see ! 214: .I s ! 215: below) ! 216: to specify a portion of a line which is to be replaced. ! 217: If it is desired to use one of ! 218: the regular expression metacharacters as an ordinary ! 219: character, that character may be preceded by `\e'. ! 220: This also applies to the character bounding the regular ! 221: expression (often ! 222: .LR / ) ! 223: and to ! 224: .L \e ! 225: itself. ! 226: .PP ! 227: To understand addressing in ! 228: .I ed ! 229: it is necessary to know that at any time there is a ! 230: .I "current line." ! 231: Generally speaking, the current line is ! 232: the last line affected by a command; however, ! 233: the exact effect on the current line ! 234: is discussed under the description of ! 235: the command. ! 236: Addresses are constructed as follows. ! 237: .TP ! 238: 1. ! 239: The character ! 240: .LR . , ! 241: customarily called `dot', ! 242: addresses the current line. ! 243: .TP ! 244: 2. ! 245: The character ! 246: .L $ ! 247: addresses the last line of the buffer. ! 248: .TP ! 249: 3. ! 250: A decimal number ! 251: .I n ! 252: addresses the ! 253: .IR n -th ! 254: line of the buffer. ! 255: .TP ! 256: 4. ! 257: .BI \'x ! 258: addresses the line marked with the name ! 259: .IR x , ! 260: which must be a lower-case letter. ! 261: Lines are marked with the ! 262: .L k ! 263: command described below. ! 264: .TP ! 265: 5. ! 266: A regular expression enclosed in slashes ! 267: .L / ! 268: addresses ! 269: the line found by searching forward from the current line ! 270: and stopping at the first line containing a ! 271: string that matches the regular expression. ! 272: If necessary the search wraps around to the beginning of the ! 273: buffer. ! 274: .TP ! 275: 6. ! 276: A regular expression enclosed in queries ! 277: .L ? ! 278: addresses ! 279: the line found by searching backward from the current line ! 280: and stopping at the first line containing ! 281: a string that matches the regular expression. ! 282: If necessary ! 283: the search wraps around to the end of the buffer. ! 284: .TP ! 285: 7. ! 286: An address followed by a plus sign ! 287: .L + ! 288: or a minus sign ! 289: .L - ! 290: followed by a decimal number specifies that address plus ! 291: (resp. minus) the indicated number of lines. ! 292: The plus sign may be omitted. ! 293: .TP ! 294: 8. ! 295: An address followed by ! 296: .L + ! 297: (or ! 298: .LR - ) ! 299: followed by a ! 300: regular expression enclosed in slashes specifies the first ! 301: matching line following (or preceding) that address. ! 302: The search wraps around if necessary. ! 303: The ! 304: .L + ! 305: may be omitted, so ! 306: .L 0/x/ ! 307: addresses the ! 308: .I first ! 309: line in the buffer with an ! 310: .LR x . ! 311: Enclosing the regular expression in ! 312: .L ? ! 313: reverses the search direction. ! 314: .TP ! 315: 9. ! 316: If an address begins with ! 317: .L + ! 318: or ! 319: .L - ! 320: the addition or subtraction is taken with respect to the current line; ! 321: e.g.\& ! 322: .L -5 ! 323: is understood to mean ! 324: .LR .-5 . ! 325: .TP ! 326: 10. ! 327: If an address ends with ! 328: .L + ! 329: or ! 330: .LR - , ! 331: then 1 is added (resp. subtracted). ! 332: As a consequence of this rule and rule 9, ! 333: the address ! 334: .L - ! 335: refers to the line before the current line. ! 336: Moreover, ! 337: trailing ! 338: .L + ! 339: and ! 340: .L - ! 341: characters ! 342: have cumulative effect, so ! 343: .L -- ! 344: refers to the current ! 345: line less 2. ! 346: .TP ! 347: 11. ! 348: To maintain compatibility with earlier versions of the editor, ! 349: the character ! 350: .L ^ ! 351: in addresses is ! 352: equivalent to ! 353: .LR - . ! 354: .PP ! 355: Commands may require zero, one, or two addresses. ! 356: Commands which require no addresses regard the presence ! 357: of an address as an error. ! 358: Commands which accept one or two addresses ! 359: assume default addresses when insufficient are given. ! 360: If more addresses are given than such a command requires, ! 361: the last one or two (depending on what is accepted) are used. ! 362: .PP ! 363: Addresses are separated from each other typically by a comma ! 364: .LR , . ! 365: They may also be separated by a semicolon ! 366: .LR ; . ! 367: In this case the current line ! 368: is set to ! 369: the previous address before the next address is interpreted. ! 370: If no address precedes a comma or semicolon, line 1 is assumed; ! 371: if no address follows, the last line of the buffer is assumed. ! 372: The second address of any two-address sequence ! 373: must correspond to a line following the line corresponding to the first address. ! 374: .PP ! 375: In the following list of ! 376: .I ed ! 377: commands, the default addresses ! 378: are shown in parentheses. ! 379: The parentheses are not part of ! 380: the address, but are used to show that the given addresses are ! 381: the default. ! 382: `Dot' means the current line. ! 383: .TP ! 384: .RB \*. \|a ! 385: .br ! 386: .ns ! 387: .TP ! 388: <text> ! 389: .br ! 390: .ns ! 391: .TP ! 392: .B . ! 393: Read the given text ! 394: and append it after the addressed line. ! 395: Dot is left ! 396: on the last line input, if there ! 397: were any, otherwise at the addressed line. ! 398: Address ! 399: .L 0 ! 400: is legal for this command; text is placed ! 401: at the beginning of the buffer. ! 402: .TP ! 403: .RB \*(.. \|b [ +- ][\fIpagesize\fP][ pln\fR] ! 404: Browse. ! 405: Print a `page', normally 20 lines. ! 406: The optional ! 407: .L + ! 408: (default) or ! 409: .L - ! 410: specifies whether the next or previous ! 411: page is to be printed. ! 412: The optional ! 413: .I pagesize ! 414: is the number of lines in a page. ! 415: The optional ! 416: .LR p , ! 417: .LR n , ! 418: or ! 419: .L l ! 420: causes printing in the specified format, initially ! 421: .LR p . ! 422: Pagesize and format are remembered between ! 423: .L b ! 424: commands. ! 425: Dot is left at the last line displayed. ! 426: .TP ! 427: .RB \*(.. \|c ! 428: .br ! 429: .ns ! 430: .TP ! 431: <text> ! 432: .br ! 433: .ns ! 434: .TP ! 435: .B . ! 436: .br ! 437: Change. ! 438: Delete the addressed lines, then accept input ! 439: text to replace these lines. ! 440: Dot is left at the last line input; if there were none, ! 441: it is left at the line preceding the deleted lines. ! 442: .TP ! 443: .RB \*(.. \|d ! 444: Delete the addressed lines from the buffer. ! 445: Dot is set to the line following the last line deleted, or to ! 446: the last line of the buffer if the deleted lines had no successor. ! 447: .TP ! 448: .BI e " filename" ! 449: Edit. ! 450: Delete the entire contents of the buffer; ! 451: then read the named file into the buffer. ! 452: Dot is set to the last line of the buffer. ! 453: The number of characters read is typed. ! 454: The file name is remembered for possible use in later ! 455: .LR e , ! 456: .LR r , ! 457: or ! 458: .L w ! 459: commands. ! 460: If ! 461: .I filename ! 462: is missing, the remembered name is used. ! 463: .TP ! 464: .BI E " filename" ! 465: Unconditional ! 466: .LR e ; ! 467: see `DIAGNOSTICS' below. ! 468: .TP ! 469: .BI f " filename" ! 470: Print the currently remembered file name. ! 471: If ! 472: .I filename ! 473: is given, ! 474: the currently remembered file name is first changed to ! 475: .I filename. ! 476: .TP ! 477: .RB \*(1$ \|g/\fIregular\ expression\fP/\fIcommand\ list\fP ! 478: .PD 0 ! 479: .TP ! 480: .RB \*(1$ \|g/\fIregular\ expression\fP/ ! 481: .TP ! 482: .RB \*(1$ \|g/\fIregular\ expression\fP ! 483: .PD ! 484: Global. ! 485: First mark every line which matches ! 486: the given ! 487: .I regular expression. ! 488: Then for every such line, execute the ! 489: .I command list ! 490: with dot initially set to that line. ! 491: A single command or the first of multiple commands ! 492: appears on the same line with the global command. ! 493: All lines of a multi-line list except the last line must end with ! 494: .LR \e . ! 495: The ! 496: .RB \&` \&. \&' ! 497: terminating input mode for an ! 498: .LR a , ! 499: .LR i , ! 500: .L c ! 501: command may be omitted if it would be on the ! 502: last line of the command list. ! 503: The commands ! 504: .L g ! 505: and ! 506: .L v ! 507: are not permitted in the command list. ! 508: Any character other than space or newline may ! 509: be used instead of ! 510: .L / ! 511: to delimit the regular expression. ! 512: The second and third forms mean ! 513: .BI g/ regular\ expression /p . ! 514: .TP ! 515: .RB (\| .\| ) \|i ! 516: .PD 0 ! 517: .TP ! 518: <text> ! 519: .TP ! 520: .B . ! 521: Insert the given text before the addressed line. ! 522: Dot is left at the last line input, or, if there were none, ! 523: at the line before the addressed line. ! 524: This command differs from the ! 525: .I a ! 526: command only in the placement of the ! 527: text. ! 528: .PD ! 529: .TP ! 530: .RB (\| .,.+1 \|) \|j ! 531: Join the addressed lines into a single line; ! 532: intermediate newlines are deleted. ! 533: Dot is left at the resulting line. ! 534: .TP ! 535: .RB \*. \|k\fIx\fP ! 536: Mark the addressed line with name ! 537: .I x, ! 538: which must be a lower-case letter. ! 539: The address form ! 540: .BI \' x ! 541: then addresses this line. ! 542: .ne 2.5 ! 543: .TP ! 544: .RB \*(.. \|l ! 545: List. ! 546: Print the addressed lines in an unambiguous way: ! 547: a tab is printed as ! 548: .LR \et , ! 549: a backspace as ! 550: .LR \eb , ! 551: backslashes as ! 552: .LR \e\e , ! 553: and non-printing characters as ! 554: printed as a backslash followed by three octal digits. ! 555: Long lines are folded, ! 556: with the second and subsequent sub-lines indented one tab stop. ! 557: If the last character in the line is a blank, ! 558: it is followed by ! 559: .LR \en . ! 560: An ! 561: .L l ! 562: may be appended, like ! 563: .LR p , ! 564: to any non-I/O command. ! 565: .TP ! 566: .RB \*(.. \|m\fIa ! 567: Move. ! 568: Reposition the addressed lines after the line ! 569: addressed by ! 570: .IR a . ! 571: Dot is left at the last moved line. ! 572: .TP ! 573: .RB \*(.. \|n ! 574: Number. ! 575: Perform ! 576: .LR p , ! 577: prefixing each line with its line number and a tab. ! 578: An ! 579: .L n ! 580: may be appended, like ! 581: .LR p , ! 582: to any non-I/O command. ! 583: .TP ! 584: .RB \*(.. \|p ! 585: Print the addressed lines. ! 586: Dot is left at the last line printed. ! 587: A ! 588: .L p ! 589: appended to any non-I/O command causes the then current line ! 590: to be printed after the command is executed. ! 591: .TP ! 592: .RB \*(.. \|P ! 593: This command is a synonym for ! 594: .LR p . ! 595: .TP ! 596: .B q ! 597: Quit the editor. ! 598: No automatic write ! 599: of a file is done. ! 600: .TP ! 601: .B Q ! 602: Quit unconditionally; see `DIAGNOSTICS' below. ! 603: .TP ! 604: .RB ( $ )\|r\ \fIfilename\fP ! 605: Read in the given file after the addressed line. ! 606: If no ! 607: .I filename ! 608: is given, the remembered file name is used. ! 609: The file name is remembered if there were no ! 610: remembered file name already. ! 611: If the read is successful, the number of characters ! 612: read is typed. ! 613: Dot is left at the last line read in from the file. ! 614: .TP ! 615: .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/ ! 616: .PD 0 ! 617: .TP ! 618: .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/g ! 619: .TP ! 620: .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP ! 621: .PD ! 622: Substitute. ! 623: Search each addressed ! 624: line for an occurrence of the specified regular expression. ! 625: On each line in which ! 626: .I n ! 627: matches are found ! 628: .RI ( n ! 629: defaults to 1 if missing), ! 630: the ! 631: .IR n th ! 632: matched string is replaced by the replacement specified. ! 633: If the global replacement indicator ! 634: .L g ! 635: appears after the command, ! 636: all subsequent matches on the line are also replaced. ! 637: It is an error for the substitution to fail on all addressed lines. ! 638: Any character other than space or newline ! 639: may be used instead of ! 640: .L / ! 641: to delimit the regular expression ! 642: and the replacement. ! 643: Dot is left at the last line substituted. ! 644: The third form means ! 645: .BI s n / regular\ expression / replacement\fP/p\fR. ! 646: The second ! 647: .L / ! 648: may be omitted if the replacement is ! 649: empty. ! 650: .IP ! 651: An ampersand ! 652: .L & ! 653: appearing in the replacement ! 654: is replaced by the string matching the regular expression. ! 655: The characters ! 656: .BI \e n, ! 657: where ! 658: .I n ! 659: is a digit, ! 660: are replaced by the text matched by the ! 661: .IR n -th ! 662: regular subexpression ! 663: enclosed between ! 664: .L \e( ! 665: and ! 666: .LR \e) . ! 667: When ! 668: nested, parenthesized subexpressions ! 669: are present, ! 670: .I n ! 671: is determined by counting occurrences of ! 672: .LR \e ( ! 673: starting from the left. ! 674: .IP ! 675: A literal ! 676: .LR & , ! 677: .LR / , ! 678: .L \e ! 679: or newline may be included in a replacement ! 680: by prefixing it with ! 681: .LR \e . ! 682: .TP ! 683: .RB \*(.. \|t\|\fIa ! 684: Transfer. ! 685: Copy the addressed lines ! 686: after the line addressed by ! 687: .I a. ! 688: Dot is left at the last line of the copy. ! 689: .TP ! 690: .RB \*(.. \|u ! 691: Undo. ! 692: Restore the preceding contents ! 693: of the current line, which must be the last line ! 694: in which a substitution was made. ! 695: .TP ! 696: .RB \*(1$ \|v/\fIregular\ expression\fP/\fIcommand\ list\fP ! 697: .PD 0 ! 698: .TP ! 699: .RB \*(1$ \|v/\fIregular\ expression\fP/ ! 700: .TP ! 701: .RB \*(1$ \|v/\fIregular\ expression\fP ! 702: .PD ! 703: This command is the same as the global command ! 704: .L g ! 705: except that the command list is executed with ! 706: dot initially set to every line ! 707: .I except ! 708: those ! 709: matching the regular expression. ! 710: .TP ! 711: .RB \*(1$ \|w " \fIfilename\fP" ! 712: Write the addressed lines onto ! 713: the given file. ! 714: If the file does not exist, ! 715: it is created with mode 666 (readable and writable by everyone). ! 716: If no ! 717: .I filename ! 718: is given, the remembered file name, if any, is used. ! 719: The file name is remembered if there were no ! 720: remembered file name already. ! 721: Dot is unchanged. ! 722: If the write is successful, the number of characters written is ! 723: printed. ! 724: .TP ! 725: .RB \*(1$ \|W " \fIfilename\fP" ! 726: Perform ! 727: .LR w , ! 728: but append to, instead of overwriting, any existing file contents. ! 729: .TP ! 730: .RB ( $ ) \|= ! 731: Print the line number of the addressed line. ! 732: Dot is unchanged. ! 733: .TP ! 734: .BI ! shell\ command ! 735: Send the remainder of the line after the ! 736: .L ! ! 737: to ! 738: .IR sh (1) ! 739: to be interpreted as a command. ! 740: Dot is unchanged. ! 741: .TP ! 742: .RB (\| .+1 )\|<newline> ! 743: An address without a command is taken as a ! 744: .L p ! 745: command. ! 746: A terminal ! 747: .L / ! 748: may be omitted from the address. ! 749: A blank line alone is equivalent to ! 750: .LR .+1p ; ! 751: it is useful ! 752: for stepping through text. ! 753: .PP ! 754: If an interrupt signal ! 755: .SM (ASCII DEL) ! 756: is sent, ! 757: .I ed ! 758: prints a ! 759: .L ? ! 760: and returns to its command level. ! 761: .PP ! 762: When reading a file, ! 763: .I ed ! 764: discards ! 765: .SM ASCII NUL ! 766: characters ! 767: and all characters after the last newline. ! 768: It refuses to read files containing non-\c ! 769: .SM ASCII ! 770: characters. ! 771: .SH FILES ! 772: .F /tmp/e* ! 773: .br ! 774: .F ed.hup ! 775: \ \ work is saved here if terminal hangs up ! 776: .SH "SEE ALSO" ! 777: .IR sam (9.1), ! 778: .IR sed (1), ! 779: .IR vi (1) ! 780: .SH DIAGNOSTICS ! 781: .BI ? name ! 782: for inaccessible file; ! 783: .L ?TMP ! 784: for temporary file overflow; ! 785: .L ? ! 786: for errors in commands or other overflows. ! 787: .PP ! 788: To protect against throwing away valuable work, ! 789: a ! 790: .L q ! 791: or ! 792: .L e ! 793: command is considered to be in error if the buffer has ! 794: been modified since the last ! 795: .LR w , ! 796: .LR q , ! 797: or ! 798: .L e ! 799: command.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.