hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

ed.1 (27616B)


      1 '\" t
      2 .\" Sccsid @(#)ed.1	1.48 (gritter) 6/22/05
      3 .\" Parts taken from ed(1), Unix 7th edition:
      4 .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
      5 .\"
      6 .\" Redistribution and use in source and binary forms, with or without
      7 .\" modification, are permitted provided that the following conditions
      8 .\" are met:
      9 .\"   Redistributions of source code and documentation must retain the
     10 .\"    above copyright notice, this list of conditions and the following
     11 .\"    disclaimer.
     12 .\"   Redistributions in binary form must reproduce the above copyright
     13 .\"    notice, this list of conditions and the following disclaimer in the
     14 .\"    documentation and/or other materials provided with the distribution.
     15 .\"   All advertising materials mentioning features or use of this software
     16 .\"    must display the following acknowledgement:
     17 .\"      This product includes software developed or owned by Caldera
     18 .\"      International, Inc.
     19 .\"   Neither the name of Caldera International, Inc. nor the names of
     20 .\"    other contributors may be used to endorse or promote products
     21 .\"    derived from this software without specific prior written permission.
     22 .\"
     23 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
     24 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
     25 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     26 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27 .\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
     28 .\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     31 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     32 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     33 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     34 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35 .TH ED 1 "6/22/05" "Heirloom Toolchest" "User Commands"
     36 .if t .ds q \(aa
     37 .if n .ds q '
     38 .SH NAME
     39 ed \- text editor
     40 .SH SYNOPSIS
     41 \fBed\fR [\fB\-\fR\ |\ \fB\-s\fR] [\fB\-p\fI\ prompt\fR] [\fIname\fR]
     42 .SH DESCRIPTION
     43 .I Ed
     44 is the standard text editor.
     45 .PP
     46 If a
     47 .I name
     48 argument is given,
     49 .I ed
     50 simulates an
     51 .I e
     52 command (see below)\| on the named file; that is to say,
     53 the file is read into
     54 .IR ed 's
     55 buffer so that it can be edited.
     56 The optional
     57 .B \-
     58 or
     59 .B \-s
     60 suppresses the printing
     61 of character counts by
     62 .IR e ,
     63 .IR r ,
     64 and
     65 .I w
     66 commands,
     67 and of the `!' after completion of a shell command.
     68 .PP
     69 With the
     70 .B \-p
     71 option,
     72 the given
     73 .I prompt
     74 string is printed before each command is read.
     75 .PP
     76 .I Ed
     77 operates on a copy of any file it is editing; changes made
     78 in the copy have no effect on the file until a
     79 .IR w ""
     80 (write)\|
     81 command is given.
     82 The copy of the text being edited resides
     83 in a temporary file called the 
     84 .IR buffer .
     85 .PP
     86 The editor supports format specifications as defined in
     87 .IR fspec (5).
     88 If the terminal is configured to expand tabulators
     89 (as enabled with
     90 .I stty tab3
     91 or
     92 .IR "stty \-tabs"),
     93 and the first line of the file being edited
     94 contains a format specification,
     95 the
     96 .I t
     97 and
     98 .I s
     99 are interpreted,
    100 that is, tabulators are expanded and lines are truncated
    101 when printing to the terminal. For example,
    102 .RS
    103 <:t\-f s72:>
    104 .sp
    105 .RE
    106 selects FORTRAN format and truncates lines at 72 characters.
    107 No expansion or truncation is performed by
    108 .I ed
    109 when input is typed to the terminal.
    110 .PP
    111 Commands to
    112 .I ed
    113 have a simple and regular structure: zero or
    114 more
    115 .I addresses
    116 followed by a single character
    117 .I command,
    118 possibly
    119 followed by parameters to the command.
    120 These addresses specify one or more lines in the buffer.
    121 Missing addresses are supplied by default.
    122 .PP
    123 In general, only one command may appear on a line.
    124 Certain commands allow the 
    125 addition of text to the buffer.
    126 While
    127 .I ed
    128 is accepting text, it is said
    129 to be in
    130 .I  "input mode."
    131 In this mode, no commands are recognized;
    132 all input is merely collected.
    133 Input mode is left by typing a period `\fB.\fR' alone at the
    134 beginning of a line.
    135 .PP
    136 .I Ed
    137 supports a limited form of
    138 .I "regular expression"
    139 notation.
    140 A regular expression specifies
    141 a set of strings of characters.
    142 A member of this set of strings is said to be
    143 .I matched
    144 by the regular expression.
    145 In the following specification for regular expressions
    146 the word `character' means any character but newline.
    147 .B /usr/5bin/ed
    148 uses simple regular expressions,
    149 whereas
    150 .BR /usr/5bin/s42/ed ,
    151 .BR /usr/5bin/posix/ed ,
    152 and
    153 .B /usr/5bin/posix2001/ed
    154 use basic regular expressions.
    155 .SS "Simple Regular Expressions"
    156 .IP 1.
    157 Any character except a special character
    158 matches itself.
    159 Special characters are
    160 the regular expression delimiter plus
    161 .RB \e\|[\| .
    162 and sometimes ^\|*\|$.
    163 .IP 2.
    164 A
    165 .B .\&
    166 matches any character.
    167 .IP 3.
    168 A \fB\e\fR followed by any character except a digit
    169 or (\|) {\|} <\|> matches that character.
    170 .IP 4.
    171 A nonempty string
    172 .I s
    173 bracketed
    174 \fB[\fI\|s\|\fB]\fR
    175 (or
    176 \fB[^\fIs\|\fB]\fR)
    177 forms a \fIbracket expression\fR that
    178 matches any character in (or not in)
    179 .I s.
    180 In 
    181 .I s,
    182 \e has no special meaning, and ] may only appear as
    183 the first letter.
    184 A substring 
    185 \fIa\fB\-\fIb\fR,
    186 with
    187 .I a
    188 and
    189 .I b
    190 in ascending ASCII order, stands for the inclusive
    191 range of ASCII characters.
    192 .IP 5.
    193 A regular expression of form 1-4 followed by \fB*\fR matches a sequence of
    194 0 or more matches of the regular expression.
    195 .IP 6.
    196 A regular expression of form 1-4
    197 followed by \fB\e{\fIm\fB,\fIn\fB\e}\fR
    198 forms an \fIinterval expression\fR that
    199 matches a sequence of \fIm\fR through \fIn\fR matches, inclusive,
    200 of the regular expression.
    201 The values of \fIm\fR and \fIn\fR must be non-negative
    202 and smaller than 256.
    203 The form \fB\e{\fIm\fB\e}\fR matches exactly \fIm\fR occurrences,
    204 \fB\e{\fIm\fB,\e}\fR matches at least \fIm\fR occurrences.
    205 .IP 7.
    206 The sequence \fB\e<\fR forces the match
    207 to occur only at the beginning of a ``variable'' or ``word'';
    208 that is, either at the beginning of a line,
    209 or just before a letter, digit or underline
    210 and after a character not one of these.
    211 .IP 8.
    212 The sequence \fB\e>\fR matches the end
    213 of a ``variable'' or ``word'',
    214 i.\|e. either the end of the line
    215 or before character which is neither a letter,
    216 nor a digit, nor the underline character.
    217 .IP 9.
    218 A regular expression,
    219 .I x,
    220 of form 1-11, parenthesized
    221 \fB\e(\fI\|x\|\fB\e)\fR
    222 is called a \fIsubexpression\fR and
    223 matches what
    224 .I x
    225 matches.
    226 .IP 10.
    227 A \fB\e\fR followed by a digit 
    228 .I n
    229 forms a \fIbackreference\fR and
    230 matches a copy of the string that the
    231 parenthesized regular expression beginning with the
    232 .IR n th
    233 \e( matched.
    234 .IP 11.
    235 A regular expression of form 1-11,
    236 .I x,
    237 followed by a regular expression of form 1-10,
    238 .I y
    239 matches a match for
    240 .I x
    241 followed by a match for
    242 .I y,
    243 with the
    244 .I x
    245 match being as long as possible while still permitting a
    246 .I y
    247 match.
    248 .IP 12.
    249 A regular expression of form 1-11 preceded by \fB^\fR
    250 (or followed by \fB$\fR), is constrained to matches that
    251 begin at the left (or end at the right) end of a line
    252 (\fIanchoring\fR).
    253 .IP 13.
    254 A regular expression of form 1-12 picks out the
    255 longest among the leftmost matches in a line.
    256 .IP 14.
    257 An empty regular expression stands for a copy of the
    258 last regular expression encountered.
    259 .SS "Basic Regular Expressions"
    260 Basic Regular Expressions add the following features
    261 to Simple Regular Expressions:
    262 .IP 15.
    263 The special character \fB*\fR, as described in 5.,
    264 and the interval expressions described in 6.
    265 can also be applied to subexpressions
    266 as described in 9.
    267 For POSIX.1-2001 utilities such as
    268 .BR /usr/5bin/posix2001/ed ,
    269 subexpressions do not match the empty string
    270 if there is a possible longer match.
    271 .IP 16.
    272 In bracket expressions as described in 4.,
    273 the following character sequences are considered special:
    274 .IP
    275 Character class expressions of the form
    276 \fB[:\fIclass\fB:]\fR.
    277 In the C LC_CTYPE locale,
    278 the classes
    279 .sp
    280 .TS
    281 l l l l.
    282 [:alnum:]	[:cntrl:]	[:lower:]	[:space:]
    283 [:alpha:]	[:digit:]	[:print:]	[:upper:]
    284 [:blank:]	[:graph:]	[:punct:]	[:xdigit:]
    285 .TE
    286 .sp
    287 are recognized;
    288 further locale-specific classes may be available.
    289 A character class expression matches any character
    290 that belongs to the given class in the current LC_CTYPE locale.
    291 .IP
    292 Collating symbol expressions of the form
    293 \fB[.\fIc\fB.]\fR,
    294 where \fIc\fR is a collating symbol
    295 in the current LC_COLLATE locale.
    296 A collating symbol expression
    297 matches the specified collating symbol.
    298 .IP
    299 Equivalence class expressions of the form
    300 \fB[=\fIc\fB=]\fR,
    301 where \fIc\fR is a collating symbol
    302 in the current LC_COLLATE locale.
    303 An equivalence class expression
    304 matches any character that has the same collating weight
    305 as \fIc\fR.
    306 .PP
    307 Regular expressions are used in addresses to specify
    308 lines and in one command
    309 (see
    310 .I s
    311 below)\|
    312 to specify a portion of a line which is to be replaced.
    313 If it is desired to use one of
    314 the regular expression metacharacters as an ordinary
    315 character, that character may be preceded by `\e'.
    316 This also applies to the character bounding the regular
    317 expression (often `/')\| and to `\e' itself.
    318 .PP
    319 To understand addressing in
    320 .I ed
    321 it is necessary to know that at any time there is a
    322 .I  "current line."
    323 Generally speaking, the current line is
    324 the last line affected by a command; however,
    325 the exact effect on the current line
    326 is discussed under the description of
    327 the command.
    328 Addresses are constructed as follows.
    329 .TP
    330 1.
    331 The character `\fB.\fR' addresses the current line.
    332 .TP
    333 2.
    334 The character `\fB$\fR' addresses the last line of the buffer.
    335 .TP
    336 3.
    337 A decimal number
    338 .I n
    339 addresses the
    340 .IR n -th
    341 line of the buffer.
    342 .TP
    343 4.
    344 `\fB\(fm\fIx\fR' addresses the line marked with the name
    345 .IR x ,
    346 which must be a lower-case letter.
    347 Lines are marked with the
    348 .I k
    349 command described below.
    350 .TP
    351 5.
    352 A regular expression enclosed in slashes `\fB/\fR' addresses
    353 the line found by searching forward from the current line
    354 and stopping at the first line containing a
    355 string that matches the regular expression.
    356 If necessary the search wraps around to the beginning of the
    357 buffer.
    358 .TP
    359 6.
    360 A regular expression enclosed in queries `\fB?\fR' addresses
    361 the line found by searching backward from the current line
    362 and stopping at the first line containing
    363 a string that matches the regular expression.
    364 If necessary
    365 the search wraps around to the end of the buffer.
    366 .TP
    367 7.
    368 An address followed by a plus sign `\fB+\fR'
    369 or a minus sign `\fB\-\fR' followed by a decimal number
    370 specifies that address plus
    371 (resp. minus)\| the indicated number of lines.
    372 The plus sign may be omitted.
    373 .TP
    374 8.
    375 If an address begins with `\fB+\fR' or `\fB\-\fR'
    376 the addition or subtraction is taken with respect to the current line;
    377 e.g. `\-5' is understood to mean `\fB.\fR\-5'.
    378 .TP
    379 9.
    380 If an address ends with `\fB+\fR' or `\fB\-\fR',
    381 then 1 is added (resp. subtracted).
    382 As a consequence of this rule and rule 8,
    383 the address `\-' refers to the line before the current line.
    384 Moreover,
    385 trailing
    386 `+' and `\-' characters
    387 have cumulative effect, so `\-\-' refers to the current
    388 line less 2.
    389 .TP
    390 10.
    391 To maintain compatibility with earlier versions of the editor,
    392 the character `\fB^\fR' in addresses is 
    393 equivalent to `\-'.
    394 .PP
    395 Commands may require zero, one, or two addresses.
    396 Commands which require no addresses regard the presence
    397 of an address as an error.
    398 Commands which accept one or two addresses
    399 assume default addresses when insufficient are given.
    400 If more addresses are given than such a command requires,
    401 the last one or two (depending on what is accepted)\| are used.
    402 .PP
    403 Addresses are separated from each other typically by a comma
    404 `\fB,\fR'.
    405 They may also be separated by a semicolon
    406 `\fB;\fR'.
    407 In this case the current line `\fB.\fR' is set to
    408 the previous address before the next address is interpreted.
    409 This feature can be used to determine the starting
    410 line for forward and backward searches (`/', `?')\|.
    411 The second address of any two-address sequence
    412 must correspond to a line following the line corresponding to the first address.
    413 .PP
    414 Omission of the first address causes
    415 the first line to be used with `,',
    416 or the current line with `;', respectively;
    417 if the second address is also omitted,
    418 the last line of the buffer is used.
    419 Thus a single `,' specifies the entire contents of the buffer,
    420 and a single `;' specifies the contents
    421 ranging from the current line to the last one.
    422 .PP
    423 In the following list of
    424 .I ed
    425 commands, the default addresses
    426 are shown in parentheses.
    427 The parentheses are not part of
    428 the address, but are used to show that the given addresses are
    429 the default.
    430 .PP
    431 As mentioned, it is generally illegal for more than one
    432 command to appear on a line.
    433 However, most commands may be suffixed by `p', `l', or `n',
    434 in which case
    435 the current line is either
    436 printed, listed, or numbered respectively
    437 in the way discussed below.
    438 .TP 5
    439 \fR(\|\fI.\|\fR)\fB\|a\fR
    440 .br
    441 .ns
    442 .TP 5
    443 <text>
    444 .br
    445 .ns
    446 .TP 5
    447 .B .
    448 .br
    449 The append command reads the given text
    450 and appends it after the addressed line.
    451 `\fB.\fR' is left
    452 on the last line input, if there
    453 were any, otherwise at the addressed line.
    454 Address `0' is legal for this command; text is placed
    455 at the beginning of the buffer.
    456 .TP 5
    457 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBc\fR
    458 .br
    459 .ns
    460 .TP 5
    461 <text>
    462 .br
    463 .ns
    464 .TP 5
    465 .B .
    466 .br
    467 The change
    468 command deletes the addressed lines, then accepts input
    469 text which replaces these lines.
    470 `\fB.\fR' is left at the last line input; if there were none,
    471 it is left at the line preceding the deleted lines.
    472 For
    473 .BR /usr/5bin/posix2001/ed ,
    474 a `0' as the first address is identical to `1'.
    475 .TP 5
    476 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBd\fR
    477 The delete command deletes the addressed lines from the buffer.
    478 The line originally after the last line deleted becomes the current line;
    479 if the lines deleted were originally at the end,
    480 the new last line becomes the current line.
    481 .TP 5
    482 \fBe\ \fIfilename\fR
    483 The edit
    484 command causes the entire contents of the buffer to be deleted,
    485 and then the named file to be read in.
    486 `\fB.\fR' is set to the last line of the buffer.
    487 The number of characters read is typed.
    488 `\fIfilename\fR' is remembered for possible use as a default file name
    489 in a subsequent
    490 .I r
    491 or
    492 .I w
    493 command.
    494 If `\fIfilename\fR' is missing, the remembered name is used.
    495 A `\fIfilename\fR' starting with a `\fB!\fR'
    496 causes the output of the shell command following this character
    497 to be read in.
    498 .TP 5
    499 \fBE\ \fIfilename\fR
    500 This command is the same as
    501 .IR e ,
    502 except that no diagnostic results when no
    503 .I w
    504 has been given since the last buffer alteration.
    505 .TP 5
    506 \fBf\ \fIfilename\fR
    507 The filename command prints the currently remembered file name.
    508 If `\fIfilename\fR' is given,
    509 the currently remembered file name is changed to `\fIfilename\fR'.
    510 .TP 5
    511 \fR(\fI1\fB,\fI$\fR)\|\fBg/\fIregular expression\fB/\fIcommand list\fR
    512 In the global
    513 command, the first step is to mark every line which matches
    514 the given \fIregular expression\fR.
    515 Then for every such line, the
    516 given \fIcommand list\fR is executed
    517 with `\fB.\fR' initially set to that line.
    518 A single command or the first of multiple commands
    519 appears on the same line with the global command.
    520 All lines of a multi-line list except the last line must be ended with `\e'.
    521 .I A,
    522 .I i,
    523 and
    524 .I c
    525 commands and associated input are permitted;
    526 the `\fB.\fR' terminating input mode may be omitted if it would be on the
    527 last line of the command list.
    528 The commands
    529 .I g
    530 and
    531 .I v
    532 are not permitted in the command list.
    533 .TP 5
    534 \fR(\fI1\fB,\fI$\fR)\|\fBG/\fIregular expression\fB/\fR
    535 The interactive global command
    536 first marks every line matching the given \fIregular expression\fR.
    537 Then each line is printed
    538 and a command is read and executed for this line.
    539 A single newline character causes the line to remain unchanged,
    540 an isolated `\fB&\fR' repeats the command given for the previous line.
    541 The command can be terminated by an interrupt signal.
    542 .TP 5
    543 .B h
    544 This command prints a verbose description for the
    545 last error encountered.
    546 .TP
    547 .B H
    548 This command acts like the
    549 .I h
    550 command,
    551 but also causes verbose descriptions to be printed
    552 on all following error conditions.
    553 Another
    554 .I H
    555 turns verbose mode off.
    556 .TP 5
    557 \fR(\|\fI.\|\fR)\|\fBi\fR
    558 .br
    559 .ns
    560 .TP 5
    561 <text>
    562 .br
    563 .ns
    564 .TP 5
    565 .B .
    566 .br
    567 This command inserts the given text before the addressed line.
    568 `\fB.\fR' is left at the last line input, or, if there were none,
    569 at the line before the addressed line.
    570 This command differs from the
    571 .I a
    572 command only in the placement of the
    573 text.
    574 For
    575 .BR /usr/5bin/posix2001/ed ,
    576 a `0' as the first address is identical to `1'.
    577 .TP 5
    578 \fR(\|\fI.\|\fB,\|\fI.+1\fR)\|\fBj\fR
    579 This command joins the addressed lines into a single line;
    580 intermediate newlines simply disappear.
    581 `\fB.\fR' is left at the resulting line.
    582 .TP 5
    583 \fR(\fI.\fR)\|\fBk\fIx\fR
    584 The mark command marks the addressed line with
    585 name
    586 .IR x ,
    587 which must be a lower-case letter.
    588 The address form `\(fm\fIx\fR' then addresses this line.
    589 .ne 2.5
    590 .TP 5
    591 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBl\fR
    592 The list command
    593 prints the addressed lines in an unambiguous way:
    594 .B /usr/5bin/ed
    595 prints
    596 non-graphic control characters in three-digit octal;
    597 .BR /usr/5bin/s42/ed ,
    598 .BR /usr/5bin/posix/ed ,
    599 and
    600 .B /usr/5bin/posix2001/ed
    601 print control characters as C-style escape sequences
    602 or in three-digit octal.
    603 Long lines are folded.
    604 The
    605 .I l
    606 command may be placed on the same line after any non-i/o
    607 command.
    608 .TP 5
    609 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBm\fIa\fR
    610 The move command repositions the addressed lines after the line
    611 addressed by
    612 .IR a .
    613 The last of the moved lines becomes the current line.
    614 .TP 5
    615 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBn\fR
    616 This command prints lines preceded by their line numbers.
    617 It otherwise acts like the
    618 .I p
    619 command described below.
    620 .TP 5
    621 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBp\fR
    622 The print command prints the addressed lines.
    623 `\fB.\fR'
    624 is left at the last line printed.
    625 The
    626 .I p
    627 command
    628 may
    629 be placed on the same line after any non-i/o command.
    630 .TP
    631 .B P
    632 This command causes a prompt to be printed
    633 before following commands are read.
    634 The default prompt is a `*' character,
    635 but can be set with the
    636 .I \-p
    637 command line option (which also enables the prompt).
    638 Another 
    639 .I P
    640 disables the prompt.
    641 .TP 5
    642 .B q
    643 The quit command causes
    644 .I ed
    645 to exit.
    646 No automatic write
    647 of a file is done.
    648 .TP 5
    649 .B Q
    650 This command is the same as
    651 .I q,
    652 except that no diagnostic results when no
    653 .I w
    654 has been given since the last buffer alteration.
    655 .TP 5
    656 \fR(\fI$\fR)\|\fBr\ \fIfilename\fR
    657 The read command
    658 reads in the given file after the addressed line.
    659 If no file name is given,
    660 the remembered file name, if any, is used
    661 (see
    662 .I e
    663 and
    664 .I f
    665 commands)\|.
    666 The file name is remembered if there was no
    667 remembered file name already.
    668 Address `0' is legal for
    669 .I r
    670 and causes the
    671 file to be read at the beginning of the buffer.
    672 If the read is successful, the number of characters
    673 read is typed.
    674 `\fB.\fR' is left at the last line read in from the file.
    675 A `filename' starting with a `\fB!\fR'
    676 causes the output of the shell command following this character
    677 to be read in.
    678 .TP 5
    679 \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fR       or,
    680 .br
    681 .ns
    682 .TP 5
    683 \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/g\fR      or,
    684 .br
    685 .ns
    686 .TP 5
    687 \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fInumber\fR
    688 The substitute command searches each addressed
    689 line for an occurrence of the specified regular expression.
    690 On each line in which a match is found,
    691 all matched strings are replaced by the replacement specified,
    692 if the global replacement indicator
    693 .RB ` g '
    694 appears after the command.
    695 If the global indicator does not appear, only the first occurrence
    696 of the matched string is replaced;
    697 if the \fInumber\fR indicator is given,
    698 the numbered occurrence is replaced.
    699 It is an error for the substitution to fail on all addressed lines.
    700 Any character other than space or new-line
    701 may be used instead of `/' to delimit the regular expression
    702 and the replacement.
    703 `\fB.\fR' is left at the last line substituted.
    704 .IP
    705 An ampersand
    706 .RB ` & '
    707 appearing in the replacement
    708 is replaced by the string matching the regular expression.
    709 The special meaning of `&' in this context may be
    710 suppressed by preceding it by
    711 .RB ` \e '.
    712 The characters `\|\fB\e\fIn\fR'
    713 where
    714 .I n
    715 is a digit,
    716 are replaced by the text matched by the
    717 .IR n -th
    718 regular subexpression
    719 enclosed between `\e(' and `\e)'.
    720 When
    721 nested, parenthesized subexpressions
    722 are present,
    723 .I n
    724 is determined by counting occurrences of `\e(' starting from the left.
    725 .IP
    726 A substitution string consisting of a single
    727 .RB ` % '
    728 causes the string given on the previous substitution to be re-used.
    729 .IP
    730 Lines may be split by substituting new-line characters into them.
    731 The new-line in the
    732 replacement string
    733 must be escaped by preceding it by
    734 .RB ` \e '.
    735 .TP 5
    736 \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBt\|\fIa\fR
    737 This command acts just like the
    738 .I m
    739 command, except that a copy of the addressed lines is placed
    740 after address
    741 .I a
    742 (which may be 0).
    743 `\fB.\fR' is left on the last line of the copy.
    744 .TP 5
    745 .B u
    746 The undo command restores
    747 the contents of the buffer
    748 before the last command was executed.
    749 If the undo command is given twice,
    750 the current state is restored.
    751 .TP 5
    752 \fR(\fI1\fB,\fI$\fR)\|\fBv/\fIregular expression\fB/\fIcommand list\fR
    753 This command is the same as the global command
    754 .I g
    755 except that the command list is executed
    756 .I g
    757 with `\fB.\fR' initially set to every line
    758 .I except
    759 those
    760 matching the regular expression.
    761 .TP 5
    762 \fR(\fI1\fB,\fI$\fR)\|\fBV/\fIregular expression\fB/\fR
    763 This command is the same as the interactive global command
    764 .I G
    765 except that the commands are read
    766 .I g
    767 with `\fB.\fR' initially set to every line
    768 .I except
    769 those
    770 matching the regular expression.
    771 .TP 5
    772 \fR(\fI1\fB,\fI$\fR)\|\fBw\ \fIfilename\fR
    773 .br
    774 The write command writes the addressed lines onto
    775 the given file.
    776 If the file does not exist,
    777 it is created mode 666 (readable and writable by everyone)\|.
    778 The file name is remembered if there was no 
    779 remembered file name already.
    780 If no file name is given,
    781 the remembered file name, if any, is used
    782 (see
    783 .I e
    784 and
    785 .I f
    786 commands)\|.
    787 `\fB.\fR' is unchanged.
    788 If the command is successful, the number of characters written is
    789 printed.
    790 A `filename' starting with a `\fB!\fR'
    791 causes the string following this character
    792 to be executed as a shell command
    793 with the addressed lines as standard input.
    794 .TP
    795 \fR(\fI1\fB,\fI$\fR)\fBW\ \fIfilename\fR
    796 This command is the same as
    797 .I w,
    798 except that the addressed lines are appended to the file.
    799 .TP 5
    800 \fR(\fI$\fR)\|\fB=\fR
    801 The line number of the addressed line is typed.
    802 `\fB.\fR' is unchanged by this command.
    803 .TP 5
    804 \fB!\fR<shell command>
    805 The remainder of the line after the `!' is sent
    806 to
    807 .IR sh (1)
    808 to be interpreted as a command.
    809 .RB ` . '
    810 is unchanged.
    811 If the command starts with a
    812 .RB ` ! ',
    813 the previous command is inserted.
    814 A
    815 .RB ` % '
    816 causes the current file name to be inserted.
    817 .TP 5
    818 \fR(\|\fI.+1\fR)\|<newline>
    819 An address alone on a line causes the addressed line to be printed.
    820 A blank line alone is equivalent to `.+1p'; it is useful
    821 for stepping through text.
    822 .PP
    823 The following commands are extensions:
    824 .TP 5
    825 \fR(\|\fI.\|\fR)\fB\|b\fR[\fIcount\fR]
    826 Prints a screenful of lines,
    827 starting at the addressed one,
    828 and browses forward in the buffer by this amount.
    829 With the optional
    830 .I count
    831 argument, the screen size for this and following
    832 .I b
    833 commands is set to the given number of lines.
    834 .TP 5
    835 .B help
    836 Causes a summary of
    837 .I ed
    838 commands along with short descriptions
    839 to be printed on the terminal.
    840 .TP 5
    841 .B N
    842 Makes the
    843 .I p
    844 command behave like the
    845 .I n
    846 command and vice-versa.
    847 If given a second time,
    848 the original semantics are restored.
    849 .TP 5
    850 \fR(\|\fI.\|\fR)\fB\|o\fR[\fIcount\fR]
    851 Prints a screenful of lines centered around the addressed one.
    852 The current line is not changed.
    853 With the optional
    854 .I count
    855 argument, the amount of lines printed above and below
    856 for this and following
    857 .I o
    858 commands is set to the given number.
    859 .TP 5
    860 .B z
    861 Performs the same actions as a
    862 .I w
    863 command followed by a
    864 .I q
    865 command.
    866 .PP
    867 If an interrupt signal is sent,
    868 .I ed
    869 prints a `?' and returns to its command level.
    870 .PP
    871 An input line that consists exactly of the two characters `\e.'
    872 causes a period `.' to be inserted with the
    873 .IR a ,
    874 .IR c ,
    875 and
    876 .IR i
    877 commands
    878 in
    879 .B /usr/5bin/ed
    880 and
    881 .BR /usr/5bin/s42/ed .
    882 .PP
    883 Some size limitations:
    884 The maximum number of bytes in the buffer
    885 corresponds to the address size;
    886 on machines with 32-bit addressing,
    887 it is 2\ G bytes,
    888 with 64-bit addressing,
    889 it is 9\ E bytes.
    890 The limit on the number of lines depends on the amount of core:
    891 each line takes 2 words.
    892 .PP
    893 If a line contains a NUL character,
    894 regular expressions cannot match beyond this character.
    895 A substitute command deletes a NUL
    896 and all following characters on the line.
    897 NUL characters in command input are discarded.
    898 If an input file does not end with a newline,
    899 .I ed
    900 prints a message and appends one.
    901 .PP
    902 Omission of the `/' character
    903 following the regular expression or the replacement string
    904 to the global and substitute commands
    905 causes the affected lines to be printed.
    906 Thus the following commands have the same effect:
    907 .RS
    908 g/pattern	g/pattern/p
    909 .br
    910 s/pattern/repl	s/pattern/repl/p
    911 .br
    912 s/pattern/	s/pattern//p
    913 .RE
    914 .SH "ENVIRONMENT VARIABLES"
    915 .TP
    916 .BR LANG ", " LC_ALL
    917 See
    918 .IR locale (7).
    919 .TP
    920 .B LC_COLLATE
    921 Affects the collation order for range expressions,
    922 equivalence classes, and collation symbols
    923 in basic regular expressions.
    924 .TP
    925 .B LC_CTYPE
    926 Determines the mapping of bytes to characters
    927 in both simple and basic regular expressions,
    928 the availability and composition of character classes
    929 in basic regular expressions,
    930 and the set of printable characters for the
    931 .I l
    932 command.
    933 .TP
    934 .B TMPDIR
    935 Determines the location of the temporary file
    936 if it contains the name of an accessible directory.
    937 .SH FILES
    938 /var/tmp/e*
    939 .br
    940 /tmp/e*
    941 .br
    942 ed.hup: work is saved here if terminal hangs up
    943 .SH "SEE ALSO"
    944 B. W. Kernighan,
    945 .I
    946 A Tutorial Introduction to the ED Text Editor
    947 .br
    948 B. W. Kernighan,
    949 .I Advanced editing on UNIX
    950 .br
    951 bfs(1),
    952 grep(1),
    953 sed(1),
    954 sh(1)
    955 .SH DIAGNOSTICS
    956 `?name' for inaccessible file;
    957 `?' for
    958 errors in commands,
    959 possibly followed by a verbose description
    960 (see the description for the
    961 .I h
    962 and
    963 .I H
    964 commands above).
    965 .PP
    966 To protect against throwing away valuable work,
    967 a
    968 .I q
    969 or
    970 .I e
    971 command is considered to be in error, unless a
    972 .I w
    973 has occurred since the last buffer change.
    974 A second
    975 .I q
    976 or
    977 .I e
    978 will be obeyed regardless.
    979 .SH NOTES
    980 A
    981 .I !\&
    982 command cannot be subject to a
    983 .I g
    984 command.
    985 .PP
    986 The LC_COLLATE variable has currently no effect.
    987 Ranges in bracket expressions are ordered
    988 as byte values in single-byte locales
    989 and as wide character values in multibyte locales;
    990 equivalence classes match the given character only,
    991 and multi-character collating elements are not available.
    992 .PP
    993 For portable programs, restrict textual data
    994 to the US-ASCII character set,
    995 set the LC_CTYPE and LC_COLLATE variables to `C' or `POSIX',
    996 and use the constructs in the second column
    997 instead of the character class expressions as follows:
    998 .RS 
    999 .sp
   1000 .TS
   1001 l l.
   1002 [[:alnum:]]	[0\-9A\-Za\-z]
   1003 [[:alpha:]]	[A\-Za\-z]
   1004 [[:blank:]]	[\fI<tab><space>\fR]
   1005 [[:cntrl:]]	[^\fI<space>\fR\-~]
   1006 [[:digit:]]	[0\-9]
   1007 [[:graph:]]	[!\-~]
   1008 [[:lower:]]	[a\-z]
   1009 [[:print:]]	[\fI<space>\fR\-~]
   1010 [[:punct:]]	[!\-/:\-@[\-`{\-~]
   1011 [[:space:]]	[\fI<tab><vt><ff><cr><space>\fR]
   1012 [[:upper:]]	[A\-Z]
   1013 [[:xdigit:]]	[0\-9a\-fA\-F]
   1014 .TE
   1015 .sp
   1016 .RE
   1017 .IR <tab> ,
   1018 .IR <space> ,
   1019 .IR <vt> ,
   1020 .IR <ff> ,
   1021 and
   1022 .I <cr>
   1023 indicate inclusion of
   1024 a literal tabulator, space, vertical tabulator, formfeed,
   1025 or carriage return character, respectively.
   1026 Do not put the
   1027 .IR <vt> ,
   1028 .IR <ff> ,
   1029 and
   1030 .I <cr>
   1031 characters into the range expression for the
   1032 .I space
   1033 class unless you actually want to match these characters.