ed.1 (13921B)
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 .IR 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 characters as 445 a backslash, an 446 .LR x , 447 and four hexadecimal digits. 448 Long lines are folded, 449 with the second and subsequent sub-lines indented one tab stop. 450 If the last character in the line is a blank, 451 it is followed by 452 .LR \en . 453 An 454 .L l 455 may be appended, like 456 .LR p , 457 to any non-I/O command. 458 .TP 459 .RB (\|\fL.,.\fP\|) \|m\fIa 460 Move. 461 Reposition the addressed lines after the line 462 addressed by 463 .IR a . 464 Dot is left at the last moved line. 465 .TP 466 .RB (\|\fL.,.\fP\|) \|n 467 Number. 468 Perform 469 .LR p , 470 prefixing each line with its line number and a tab. 471 An 472 .L n 473 may be appended, like 474 .LR p , 475 to any non-I/O command. 476 .TP 477 .RB (\|\fL.,.\fP\|) \|p 478 Print the addressed lines. 479 Dot is left at the last line printed. 480 A 481 .L p 482 appended to any non-I/O command causes the then current line 483 to be printed after the command is executed. 484 .TP 485 .RB (\|\fL.,.\fP\|) \|P 486 This command is a synonym for 487 .LR p . 488 .TP 489 .B q 490 Quit the editor. 491 No automatic write 492 of a file is done. 493 A 494 .L q 495 or 496 .L e 497 command is considered to be in error if the buffer has 498 been modified since the last 499 .LR w , 500 .LR q , 501 or 502 .L e 503 command. 504 .TP 505 .B Q 506 Quit unconditionally. 507 .TP 508 .RB ( $ )\|r\ \fIfilename\fP 509 Read in the given file after the addressed line. 510 If no 511 .I filename 512 is given, the remembered file name is used. 513 The file name is remembered if there were no 514 remembered file name already. 515 If the read is successful, the number of characters 516 read is printed. 517 Dot is left at the last line read from the file. 518 .TP 519 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/ 520 .PD 0 521 .TP 522 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/g 523 .TP 524 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP 525 .PD 526 Substitute. 527 Search each addressed 528 line for an occurrence of the specified regular expression. 529 On each line in which 530 .I n 531 matches are found 532 .RI ( n 533 defaults to 1 if missing), 534 the 535 .IR n th 536 matched string is replaced by the replacement specified. 537 If the global replacement indicator 538 .L g 539 appears after the command, 540 all subsequent matches on the line are also replaced. 541 It is an error for the substitution to fail on all addressed lines. 542 Any character other than space or newline 543 may be used instead of 544 .L / 545 to delimit the regular expression 546 and the replacement. 547 Dot is left at the last line substituted. 548 The third form means 549 .BI s n / regular\ expression / replacement\fP/p\f1. 550 The second 551 .L / 552 may be omitted if the replacement is 553 empty. 554 .IP 555 An ampersand 556 .L & 557 appearing in the replacement 558 is replaced by the string matching the regular expression. 559 The characters 560 .BI \e n\f1, 561 where 562 .I n 563 is a digit, 564 are replaced by the text matched by the 565 .IR n -th 566 regular subexpression 567 enclosed between 568 .L ( 569 and 570 .LR ) . 571 When 572 nested parenthesized subexpressions 573 are present, 574 .I n 575 is determined by counting occurrences of 576 .L ( 577 starting from the left. 578 .IP 579 A literal 580 .LR & , 581 .LR / , 582 .L \e 583 or newline may be included in a replacement 584 by prefixing it with 585 .LR \e . 586 .TP 587 .RB (\|\fL.,.\fP\|) \|t\|\fIa 588 Transfer. 589 Copy the addressed lines 590 after the line addressed by 591 .IR a . 592 Dot is left at the last line of the copy. 593 .TP 594 .RB (\|\fL.,.\fP\|) \|u 595 Undo. 596 Restore the preceding contents 597 of the first addressed line (sic), which must be the last line 598 in which a substitution was made (double sic). 599 .TP 600 .RB (\|\fL1,$\fP\|) \|v/\fIregular\ expression\fP/\fIcommand\ list\fP 601 This command is the same as the global command 602 .L g 603 except that the command list is executed with 604 dot initially set to every line 605 .I except 606 those 607 matching the regular expression. 608 .TP 609 .RB (\|\fL1,$\fP\|) \|w " \fIfilename\fP" 610 Write the addressed lines to 611 the given file. 612 If the file does not exist, 613 it is created with mode 666 (readable and writable by everyone). 614 If no 615 .I filename 616 is given, the remembered file name, if any, is used. 617 The file name is remembered if there were no 618 remembered file name already. 619 Dot is unchanged. 620 If the write is successful, the number of characters written is 621 printed. 622 .TP 623 .RB (\|\fL1,$\fP\|) \|W " \fIfilename\fP" 624 Perform 625 .LR w , 626 but append to, instead of overwriting, any existing file contents. 627 .TP 628 .RB ( $ ) \|= 629 Print the line number of the addressed line. 630 Dot is unchanged. 631 .TP 632 .BI ! shell\ command 633 Send the remainder of the line after the 634 .L ! 635 to 636 .IR rc (1) 637 to be interpreted as a command. 638 Dot is unchanged. 639 .TP 640 .RB (\| .+1 )\|<newline> 641 An address without a command is taken as a 642 .L p 643 command. 644 A terminal 645 .L / 646 may be omitted from the address. 647 A blank line alone is equivalent to 648 .LR .+1p ; 649 it is useful 650 for stepping through text. 651 .PP 652 If an interrupt signal 653 .SM (DEL) 654 is sent, 655 .I ed 656 prints a 657 .L ? 658 and returns to its command level. 659 .PP 660 When reading a file, 661 .I ed 662 discards 663 .SM NUL 664 characters 665 and all characters after the last newline. 666 .SH FILES 667 .B /tmp/e* 668 .br 669 .B ed.hup 670 \ \ work is saved here if terminal hangs up 671 .SH SOURCE 672 .B \*9/src/cmd/ed.c 673 .SH "SEE ALSO" 674 .IR sam (1), 675 .IR sed (1), 676 .IR regexp (7) 677 .SH DIAGNOSTICS 678 .BI ? name 679 for inaccessible file; 680 .L ?TMP 681 for temporary file overflow; 682 .L ? 683 for errors in commands or other overflows.