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