heirloom-ed
diff ed.1 @ 0:1493bea5ac22
Initial version of the standalone heirloom-ed
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Mon, 05 Sep 2011 16:31:35 +0200 |
parents | |
children | a09d0630f05b |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ed.1 Mon Sep 05 16:31:35 2011 +0200 1.3 @@ -0,0 +1,914 @@ 1.4 +'\" t 1.5 +.\" Sccsid @(#)ed.1 1.48 (gritter) 6/22/05 1.6 +.\" Parts taken from ed(1), Unix 7th edition: 1.7 +.\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. 1.8 +.\" 1.9 +.\" Redistribution and use in source and binary forms, with or without 1.10 +.\" modification, are permitted provided that the following conditions 1.11 +.\" are met: 1.12 +.\" Redistributions of source code and documentation must retain the 1.13 +.\" above copyright notice, this list of conditions and the following 1.14 +.\" disclaimer. 1.15 +.\" Redistributions in binary form must reproduce the above copyright 1.16 +.\" notice, this list of conditions and the following disclaimer in the 1.17 +.\" documentation and/or other materials provided with the distribution. 1.18 +.\" All advertising materials mentioning features or use of this software 1.19 +.\" must display the following acknowledgement: 1.20 +.\" This product includes software developed or owned by Caldera 1.21 +.\" International, Inc. 1.22 +.\" Neither the name of Caldera International, Inc. nor the names of 1.23 +.\" other contributors may be used to endorse or promote products 1.24 +.\" derived from this software without specific prior written permission. 1.25 +.\" 1.26 +.\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 1.27 +.\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR 1.28 +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1.29 +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.30 +.\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 1.31 +.\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.32 +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.33 +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 1.34 +.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 1.35 +.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 1.36 +.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 1.37 +.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.38 +.TH ED 1 "6/22/05" "Heirloom Toolchest" "User Commands" 1.39 +.if t .ds q \(aa 1.40 +.if n .ds q ' 1.41 +.SH NAME 1.42 +ed \- text editor 1.43 +.SH SYNOPSIS 1.44 +\fBed\fR [\fB\-\fR\ |\ \fB\-s\fR] [\fB\-p\fI\ prompt\fR] [\fIname\fR] 1.45 +.SH DESCRIPTION 1.46 +.I Ed 1.47 +is the standard text editor. 1.48 +.PP 1.49 +If a 1.50 +.I name 1.51 +argument is given, 1.52 +.I ed 1.53 +simulates an 1.54 +.I e 1.55 +command (see below)\| on the named file; that is to say, 1.56 +the file is read into 1.57 +.IR ed 's 1.58 +buffer so that it can be edited. 1.59 +The optional 1.60 +.B \- 1.61 +or 1.62 +.B \-s 1.63 +suppresses the printing 1.64 +of character counts by 1.65 +.IR e , 1.66 +.IR r , 1.67 +and 1.68 +.I w 1.69 +commands, 1.70 +and of the `!' after completion of a shell command. 1.71 +.PP 1.72 +With the 1.73 +.B \-p 1.74 +option, 1.75 +the given 1.76 +.I prompt 1.77 +string is printed before each command is read. 1.78 +.PP 1.79 +.I Ed 1.80 +operates on a copy of any file it is editing; changes made 1.81 +in the copy have no effect on the file until a 1.82 +.IR w "" 1.83 +(write)\| 1.84 +command is given. 1.85 +The copy of the text being edited resides 1.86 +in a temporary file called the 1.87 +.IR buffer . 1.88 +.PP 1.89 +The editor supports format specifications as defined in 1.90 +.IR fspec (5). 1.91 +If the terminal is configured to expand tabulators 1.92 +(as enabled with 1.93 +.I stty tab3 1.94 +or 1.95 +.IR "stty \-tabs"), 1.96 +and the first line of the file being edited 1.97 +contains a format specification, 1.98 +the 1.99 +.I t 1.100 +and 1.101 +.I s 1.102 +are interpreted, 1.103 +that is, tabulators are expanded and lines are truncated 1.104 +when printing to the terminal. For example, 1.105 +.RS 1.106 +<:t\-f s72:> 1.107 +.sp 1.108 +.RE 1.109 +selects FORTRAN format and truncates lines at 72 characters. 1.110 +No expansion or truncation is performed by 1.111 +.I ed 1.112 +when input is typed to the terminal. 1.113 +.PP 1.114 +Commands to 1.115 +.I ed 1.116 +have a simple and regular structure: zero or 1.117 +more 1.118 +.I addresses 1.119 +followed by a single character 1.120 +.I command, 1.121 +possibly 1.122 +followed by parameters to the command. 1.123 +These addresses specify one or more lines in the buffer. 1.124 +Missing addresses are supplied by default. 1.125 +.PP 1.126 +In general, only one command may appear on a line. 1.127 +Certain commands allow the 1.128 +addition of text to the buffer. 1.129 +While 1.130 +.I ed 1.131 +is accepting text, it is said 1.132 +to be in 1.133 +.I "input mode." 1.134 +In this mode, no commands are recognized; 1.135 +all input is merely collected. 1.136 +Input mode is left by typing a period `\fB.\fR' alone at the 1.137 +beginning of a line. 1.138 +.PP 1.139 +.I Ed 1.140 +supports a limited form of 1.141 +.I "regular expression" 1.142 +notation. 1.143 +A regular expression specifies 1.144 +a set of strings of characters. 1.145 +A member of this set of strings is said to be 1.146 +.I matched 1.147 +by the regular expression. 1.148 +In the following specification for regular expressions 1.149 +the word `character' means any character but newline. 1.150 +.B ed 1.151 +uses simple regular expressions. 1.152 +.SS "Simple Regular Expressions" 1.153 +.IP 1. 1.154 +Any character except a special character 1.155 +matches itself. 1.156 +Special characters are 1.157 +the regular expression delimiter plus 1.158 +.RB \e\|[\| . 1.159 +and sometimes ^\|*\|$. 1.160 +.IP 2. 1.161 +A 1.162 +.B .\& 1.163 +matches any character. 1.164 +.IP 3. 1.165 +A \fB\e\fR followed by any character except a digit 1.166 +or (\|) {\|} <\|> matches that character. 1.167 +.IP 4. 1.168 +A nonempty string 1.169 +.I s 1.170 +bracketed 1.171 +\fB[\fI\|s\|\fB]\fR 1.172 +(or 1.173 +\fB[^\fIs\|\fB]\fR) 1.174 +forms a \fIbracket expression\fR that 1.175 +matches any character in (or not in) 1.176 +.I s. 1.177 +In 1.178 +.I s, 1.179 +\e has no special meaning, and ] may only appear as 1.180 +the first letter. 1.181 +A substring 1.182 +\fIa\fB\-\fIb\fR, 1.183 +with 1.184 +.I a 1.185 +and 1.186 +.I b 1.187 +in ascending ASCII order, stands for the inclusive 1.188 +range of ASCII characters. 1.189 +.IP 5. 1.190 +A regular expression of form 1-4 followed by \fB*\fR matches a sequence of 1.191 +0 or more matches of the regular expression. 1.192 +.IP 6. 1.193 +A regular expression of form 1-4 1.194 +followed by \fB\e{\fIm\fB,\fIn\fB\e}\fR 1.195 +forms an \fIinterval expression\fR that 1.196 +matches a sequence of \fIm\fR through \fIn\fR matches, inclusive, 1.197 +of the regular expression. 1.198 +The values of \fIm\fR and \fIn\fR must be non-negative 1.199 +and smaller than 256. 1.200 +The form \fB\e{\fIm\fB\e}\fR matches exactly \fIm\fR occurrences, 1.201 +\fB\e{\fIm\fB,\e}\fR matches at least \fIm\fR occurrences. 1.202 +.IP 7. 1.203 +The sequence \fB\e<\fR forces the match 1.204 +to occur only at the beginning of a ``variable'' or ``word''; 1.205 +that is, either at the beginning of a line, 1.206 +or just before a letter, digit or underline 1.207 +and after a character not one of these. 1.208 +.IP 8. 1.209 +The sequence \fB\e>\fR matches the end 1.210 +of a ``variable'' or ``word'', 1.211 +i.\|e. either the end of the line 1.212 +or before character which is neither a letter, 1.213 +nor a digit, nor the underline character. 1.214 +.IP 9. 1.215 +A regular expression, 1.216 +.I x, 1.217 +of form 1-11, parenthesized 1.218 +\fB\e(\fI\|x\|\fB\e)\fR 1.219 +is called a \fIsubexpression\fR and 1.220 +matches what 1.221 +.I x 1.222 +matches. 1.223 +.IP 10. 1.224 +A \fB\e\fR followed by a digit 1.225 +.I n 1.226 +forms a \fIbackreference\fR and 1.227 +matches a copy of the string that the 1.228 +parenthesized regular expression beginning with the 1.229 +.IR n th 1.230 +\e( matched. 1.231 +.IP 11. 1.232 +A regular expression of form 1-11, 1.233 +.I x, 1.234 +followed by a regular expression of form 1-10, 1.235 +.I y 1.236 +matches a match for 1.237 +.I x 1.238 +followed by a match for 1.239 +.I y, 1.240 +with the 1.241 +.I x 1.242 +match being as long as possible while still permitting a 1.243 +.I y 1.244 +match. 1.245 +.IP 12. 1.246 +A regular expression of form 1-11 preceded by \fB^\fR 1.247 +(or followed by \fB$\fR), is constrained to matches that 1.248 +begin at the left (or end at the right) end of a line 1.249 +(\fIanchoring\fR). 1.250 +.IP 13. 1.251 +A regular expression of form 1-12 picks out the 1.252 +longest among the leftmost matches in a line. 1.253 +.IP 14. 1.254 +An empty regular expression stands for a copy of the 1.255 +last regular expression encountered. 1.256 +.PP 1.257 +Regular expressions are used in addresses to specify 1.258 +lines and in one command 1.259 +(see 1.260 +.I s 1.261 +below)\| 1.262 +to specify a portion of a line which is to be replaced. 1.263 +If it is desired to use one of 1.264 +the regular expression metacharacters as an ordinary 1.265 +character, that character may be preceded by `\e'. 1.266 +This also applies to the character bounding the regular 1.267 +expression (often `/')\| and to `\e' itself. 1.268 +.PP 1.269 +To understand addressing in 1.270 +.I ed 1.271 +it is necessary to know that at any time there is a 1.272 +.I "current line." 1.273 +Generally speaking, the current line is 1.274 +the last line affected by a command; however, 1.275 +the exact effect on the current line 1.276 +is discussed under the description of 1.277 +the command. 1.278 +Addresses are constructed as follows. 1.279 +.TP 1.280 +1. 1.281 +The character `\fB.\fR' addresses the current line. 1.282 +.TP 1.283 +2. 1.284 +The character `\fB$\fR' addresses the last line of the buffer. 1.285 +.TP 1.286 +3. 1.287 +A decimal number 1.288 +.I n 1.289 +addresses the 1.290 +.IR n -th 1.291 +line of the buffer. 1.292 +.TP 1.293 +4. 1.294 +`\fB\(fm\fIx\fR' addresses the line marked with the name 1.295 +.IR x , 1.296 +which must be a lower-case letter. 1.297 +Lines are marked with the 1.298 +.I k 1.299 +command described below. 1.300 +.TP 1.301 +5. 1.302 +A regular expression enclosed in slashes `\fB/\fR' addresses 1.303 +the line found by searching forward from the current line 1.304 +and stopping at the first line containing a 1.305 +string that matches the regular expression. 1.306 +If necessary the search wraps around to the beginning of the 1.307 +buffer. 1.308 +.TP 1.309 +6. 1.310 +A regular expression enclosed in queries `\fB?\fR' addresses 1.311 +the line found by searching backward from the current line 1.312 +and stopping at the first line containing 1.313 +a string that matches the regular expression. 1.314 +If necessary 1.315 +the search wraps around to the end of the buffer. 1.316 +.TP 1.317 +7. 1.318 +An address followed by a plus sign `\fB+\fR' 1.319 +or a minus sign `\fB\-\fR' followed by a decimal number 1.320 +specifies that address plus 1.321 +(resp. minus)\| the indicated number of lines. 1.322 +The plus sign may be omitted. 1.323 +.TP 1.324 +8. 1.325 +If an address begins with `\fB+\fR' or `\fB\-\fR' 1.326 +the addition or subtraction is taken with respect to the current line; 1.327 +e.g. `\-5' is understood to mean `\fB.\fR\-5'. 1.328 +.TP 1.329 +9. 1.330 +If an address ends with `\fB+\fR' or `\fB\-\fR', 1.331 +then 1 is added (resp. subtracted). 1.332 +As a consequence of this rule and rule 8, 1.333 +the address `\-' refers to the line before the current line. 1.334 +Moreover, 1.335 +trailing 1.336 +`+' and `\-' characters 1.337 +have cumulative effect, so `\-\-' refers to the current 1.338 +line less 2. 1.339 +.TP 1.340 +10. 1.341 +To maintain compatibility with earlier versions of the editor, 1.342 +the character `\fB^\fR' in addresses is 1.343 +equivalent to `\-'. 1.344 +.PP 1.345 +Commands may require zero, one, or two addresses. 1.346 +Commands which require no addresses regard the presence 1.347 +of an address as an error. 1.348 +Commands which accept one or two addresses 1.349 +assume default addresses when insufficient are given. 1.350 +If more addresses are given than such a command requires, 1.351 +the last one or two (depending on what is accepted)\| are used. 1.352 +.PP 1.353 +Addresses are separated from each other typically by a comma 1.354 +`\fB,\fR'. 1.355 +They may also be separated by a semicolon 1.356 +`\fB;\fR'. 1.357 +In this case the current line `\fB.\fR' is set to 1.358 +the previous address before the next address is interpreted. 1.359 +This feature can be used to determine the starting 1.360 +line for forward and backward searches (`/', `?')\|. 1.361 +The second address of any two-address sequence 1.362 +must correspond to a line following the line corresponding to the first address. 1.363 +.PP 1.364 +Omission of the first address causes 1.365 +the first line to be used with `,', 1.366 +or the current line with `;', respectively; 1.367 +if the second address is also omitted, 1.368 +the last line of the buffer is used. 1.369 +Thus a single `,' specifies the entire contents of the buffer, 1.370 +and a single `;' specifies the contents 1.371 +ranging from the current line to the last one. 1.372 +.PP 1.373 +In the following list of 1.374 +.I ed 1.375 +commands, the default addresses 1.376 +are shown in parentheses. 1.377 +The parentheses are not part of 1.378 +the address, but are used to show that the given addresses are 1.379 +the default. 1.380 +.PP 1.381 +As mentioned, it is generally illegal for more than one 1.382 +command to appear on a line. 1.383 +However, most commands may be suffixed by `p', `l', or `n', 1.384 +in which case 1.385 +the current line is either 1.386 +printed, listed, or numbered respectively 1.387 +in the way discussed below. 1.388 +.TP 5 1.389 +\fR(\|\fI.\|\fR)\fB\|a\fR 1.390 +.br 1.391 +.ns 1.392 +.TP 5 1.393 +<text> 1.394 +.br 1.395 +.ns 1.396 +.TP 5 1.397 +.B . 1.398 +.br 1.399 +The append command reads the given text 1.400 +and appends it after the addressed line. 1.401 +`\fB.\fR' is left 1.402 +on the last line input, if there 1.403 +were any, otherwise at the addressed line. 1.404 +Address `0' is legal for this command; text is placed 1.405 +at the beginning of the buffer. 1.406 +.TP 5 1.407 +\fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBc\fR 1.408 +.br 1.409 +.ns 1.410 +.TP 5 1.411 +<text> 1.412 +.br 1.413 +.ns 1.414 +.TP 5 1.415 +.B . 1.416 +.br 1.417 +The change 1.418 +command deletes the addressed lines, then accepts input 1.419 +text which replaces these lines. 1.420 +`\fB.\fR' is left at the last line input; if there were none, 1.421 +it is left at the line preceding the deleted lines. 1.422 +.TP 5 1.423 +\fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBd\fR 1.424 +The delete command deletes the addressed lines from the buffer. 1.425 +The line originally after the last line deleted becomes the current line; 1.426 +if the lines deleted were originally at the end, 1.427 +the new last line becomes the current line. 1.428 +.TP 5 1.429 +\fBe\ \fIfilename\fR 1.430 +The edit 1.431 +command causes the entire contents of the buffer to be deleted, 1.432 +and then the named file to be read in. 1.433 +`\fB.\fR' is set to the last line of the buffer. 1.434 +The number of characters read is typed. 1.435 +`\fIfilename\fR' is remembered for possible use as a default file name 1.436 +in a subsequent 1.437 +.I r 1.438 +or 1.439 +.I w 1.440 +command. 1.441 +If `\fIfilename\fR' is missing, the remembered name is used. 1.442 +A `\fIfilename\fR' starting with a `\fB!\fR' 1.443 +causes the output of the shell command following this character 1.444 +to be read in. 1.445 +.TP 5 1.446 +\fBE\ \fIfilename\fR 1.447 +This command is the same as 1.448 +.IR e , 1.449 +except that no diagnostic results when no 1.450 +.I w 1.451 +has been given since the last buffer alteration. 1.452 +.TP 5 1.453 +\fBf\ \fIfilename\fR 1.454 +The filename command prints the currently remembered file name. 1.455 +If `\fIfilename\fR' is given, 1.456 +the currently remembered file name is changed to `\fIfilename\fR'. 1.457 +.TP 5 1.458 +\fR(\fI1\fB,\fI$\fR)\|\fBg/\fIregular expression\fB/\fIcommand list\fR 1.459 +In the global 1.460 +command, the first step is to mark every line which matches 1.461 +the given \fIregular expression\fR. 1.462 +Then for every such line, the 1.463 +given \fIcommand list\fR is executed 1.464 +with `\fB.\fR' initially set to that line. 1.465 +A single command or the first of multiple commands 1.466 +appears on the same line with the global command. 1.467 +All lines of a multi-line list except the last line must be ended with `\e'. 1.468 +.I A, 1.469 +.I i, 1.470 +and 1.471 +.I c 1.472 +commands and associated input are permitted; 1.473 +the `\fB.\fR' terminating input mode may be omitted if it would be on the 1.474 +last line of the command list. 1.475 +The commands 1.476 +.I g 1.477 +and 1.478 +.I v 1.479 +are not permitted in the command list. 1.480 +.TP 5 1.481 +\fR(\fI1\fB,\fI$\fR)\|\fBG/\fIregular expression\fB/\fR 1.482 +The interactive global command 1.483 +first marks every line matching the given \fIregular expression\fR. 1.484 +Then each line is printed 1.485 +and a command is read and executed for this line. 1.486 +A single newline character causes the line to remain unchanged, 1.487 +an isolated `\fB&\fR' repeats the command given for the previous line. 1.488 +The command can be terminated by an interrupt signal. 1.489 +.TP 5 1.490 +.B h 1.491 +This command prints a verbose description for the 1.492 +last error encountered. 1.493 +.TP 1.494 +.B H 1.495 +This command acts like the 1.496 +.I h 1.497 +command, 1.498 +but also causes verbose descriptions to be printed 1.499 +on all following error conditions. 1.500 +Another 1.501 +.I H 1.502 +turns verbose mode off. 1.503 +.TP 5 1.504 +\fR(\|\fI.\|\fR)\|\fBi\fR 1.505 +.br 1.506 +.ns 1.507 +.TP 5 1.508 +<text> 1.509 +.br 1.510 +.ns 1.511 +.TP 5 1.512 +.B . 1.513 +.br 1.514 +This command inserts the given text before the addressed line. 1.515 +`\fB.\fR' is left at the last line input, or, if there were none, 1.516 +at the line before the addressed line. 1.517 +This command differs from the 1.518 +.I a 1.519 +command only in the placement of the 1.520 +text. 1.521 +.TP 5 1.522 +\fR(\|\fI.\|\fB,\|\fI.+1\fR)\|\fBj\fR 1.523 +This command joins the addressed lines into a single line; 1.524 +intermediate newlines simply disappear. 1.525 +`\fB.\fR' is left at the resulting line. 1.526 +.TP 5 1.527 +\fR(\fI.\fR)\|\fBk\fIx\fR 1.528 +The mark command marks the addressed line with 1.529 +name 1.530 +.IR x , 1.531 +which must be a lower-case letter. 1.532 +The address form `\(fm\fIx\fR' then addresses this line. 1.533 +.ne 2.5 1.534 +.TP 5 1.535 +\fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBl\fR 1.536 +The list command 1.537 +prints the addressed lines in an unambiguous way: 1.538 +non-graphic control characters are printed in three-digit octal; 1.539 +Long lines are folded. 1.540 +The 1.541 +.I l 1.542 +command may be placed on the same line after any non-i/o 1.543 +command. 1.544 +.TP 5 1.545 +\fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBm\fIa\fR 1.546 +The move command repositions the addressed lines after the line 1.547 +addressed by 1.548 +.IR a . 1.549 +The last of the moved lines becomes the current line. 1.550 +.TP 5 1.551 +\fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBn\fR 1.552 +This command prints lines preceded by their line numbers. 1.553 +It otherwise acts like the 1.554 +.I p 1.555 +command described below. 1.556 +.TP 5 1.557 +\fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBp\fR 1.558 +The print command prints the addressed lines. 1.559 +`\fB.\fR' 1.560 +is left at the last line printed. 1.561 +The 1.562 +.I p 1.563 +command 1.564 +may 1.565 +be placed on the same line after any non-i/o command. 1.566 +.TP 1.567 +.B P 1.568 +This command causes a prompt to be printed 1.569 +before following commands are read. 1.570 +The default prompt is a `*' character, 1.571 +but can be set with the 1.572 +.I \-p 1.573 +command line option (which also enables the prompt). 1.574 +Another 1.575 +.I P 1.576 +disables the prompt. 1.577 +.TP 5 1.578 +.B q 1.579 +The quit command causes 1.580 +.I ed 1.581 +to exit. 1.582 +No automatic write 1.583 +of a file is done. 1.584 +.TP 5 1.585 +.B Q 1.586 +This command is the same as 1.587 +.I q, 1.588 +except that no diagnostic results when no 1.589 +.I w 1.590 +has been given since the last buffer alteration. 1.591 +.TP 5 1.592 +\fR(\fI$\fR)\|\fBr\ \fIfilename\fR 1.593 +The read command 1.594 +reads in the given file after the addressed line. 1.595 +If no file name is given, 1.596 +the remembered file name, if any, is used 1.597 +(see 1.598 +.I e 1.599 +and 1.600 +.I f 1.601 +commands)\|. 1.602 +The file name is remembered if there was no 1.603 +remembered file name already. 1.604 +Address `0' is legal for 1.605 +.I r 1.606 +and causes the 1.607 +file to be read at the beginning of the buffer. 1.608 +If the read is successful, the number of characters 1.609 +read is typed. 1.610 +`\fB.\fR' is left at the last line read in from the file. 1.611 +A `filename' starting with a `\fB!\fR' 1.612 +causes the output of the shell command following this character 1.613 +to be read in. 1.614 +.TP 5 1.615 +\fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fR or, 1.616 +.br 1.617 +.ns 1.618 +.TP 5 1.619 +\fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/g\fR or, 1.620 +.br 1.621 +.ns 1.622 +.TP 5 1.623 +\fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fInumber\fR 1.624 +The substitute command searches each addressed 1.625 +line for an occurrence of the specified regular expression. 1.626 +On each line in which a match is found, 1.627 +all matched strings are replaced by the replacement specified, 1.628 +if the global replacement indicator 1.629 +.RB ` g ' 1.630 +appears after the command. 1.631 +If the global indicator does not appear, only the first occurrence 1.632 +of the matched string is replaced; 1.633 +if the \fInumber\fR indicator is given, 1.634 +the numbered occurrence is replaced. 1.635 +It is an error for the substitution to fail on all addressed lines. 1.636 +Any character other than space or new-line 1.637 +may be used instead of `/' to delimit the regular expression 1.638 +and the replacement. 1.639 +`\fB.\fR' is left at the last line substituted. 1.640 +.IP 1.641 +An ampersand 1.642 +.RB ` & ' 1.643 +appearing in the replacement 1.644 +is replaced by the string matching the regular expression. 1.645 +The special meaning of `&' in this context may be 1.646 +suppressed by preceding it by 1.647 +.RB ` \e '. 1.648 +The characters `\|\fB\e\fIn\fR' 1.649 +where 1.650 +.I n 1.651 +is a digit, 1.652 +are replaced by the text matched by the 1.653 +.IR n -th 1.654 +regular subexpression 1.655 +enclosed between `\e(' and `\e)'. 1.656 +When 1.657 +nested, parenthesized subexpressions 1.658 +are present, 1.659 +.I n 1.660 +is determined by counting occurrences of `\e(' starting from the left. 1.661 +.IP 1.662 +A substitution string consisting of a single 1.663 +.RB ` % ' 1.664 +causes the string given on the previous substitution to be re-used. 1.665 +.IP 1.666 +Lines may be split by substituting new-line characters into them. 1.667 +The new-line in the 1.668 +replacement string 1.669 +must be escaped by preceding it by 1.670 +.RB ` \e '. 1.671 +.TP 5 1.672 +\fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBt\|\fIa\fR 1.673 +This command acts just like the 1.674 +.I m 1.675 +command, except that a copy of the addressed lines is placed 1.676 +after address 1.677 +.I a 1.678 +(which may be 0). 1.679 +`\fB.\fR' is left on the last line of the copy. 1.680 +.TP 5 1.681 +.B u 1.682 +The undo command restores 1.683 +the contents of the buffer 1.684 +before the last command was executed. 1.685 +If the undo command is given twice, 1.686 +the current state is restored. 1.687 +.TP 5 1.688 +\fR(\fI1\fB,\fI$\fR)\|\fBv/\fIregular expression\fB/\fIcommand list\fR 1.689 +This command is the same as the global command 1.690 +.I g 1.691 +except that the command list is executed 1.692 +.I g 1.693 +with `\fB.\fR' initially set to every line 1.694 +.I except 1.695 +those 1.696 +matching the regular expression. 1.697 +.TP 5 1.698 +\fR(\fI1\fB,\fI$\fR)\|\fBV/\fIregular expression\fB/\fR 1.699 +This command is the same as the interactive global command 1.700 +.I G 1.701 +except that the commands are read 1.702 +.I g 1.703 +with `\fB.\fR' initially set to every line 1.704 +.I except 1.705 +those 1.706 +matching the regular expression. 1.707 +.TP 5 1.708 +\fR(\fI1\fB,\fI$\fR)\|\fBw\ \fIfilename\fR 1.709 +.br 1.710 +The write command writes the addressed lines onto 1.711 +the given file. 1.712 +If the file does not exist, 1.713 +it is created mode 666 (readable and writable by everyone)\|. 1.714 +The file name is remembered if there was no 1.715 +remembered file name already. 1.716 +If no file name is given, 1.717 +the remembered file name, if any, is used 1.718 +(see 1.719 +.I e 1.720 +and 1.721 +.I f 1.722 +commands)\|. 1.723 +`\fB.\fR' is unchanged. 1.724 +If the command is successful, the number of characters written is 1.725 +printed. 1.726 +A `filename' starting with a `\fB!\fR' 1.727 +causes the string following this character 1.728 +to be executed as a shell command 1.729 +with the addressed lines as standard input. 1.730 +.TP 1.731 +\fR(\fI1\fB,\fI$\fR)\fBW\ \fIfilename\fR 1.732 +This command is the same as 1.733 +.I w, 1.734 +except that the addressed lines are appended to the file. 1.735 +.TP 5 1.736 +\fR(\fI$\fR)\|\fB=\fR 1.737 +The line number of the addressed line is typed. 1.738 +`\fB.\fR' is unchanged by this command. 1.739 +.TP 5 1.740 +\fB!\fR<shell command> 1.741 +The remainder of the line after the `!' is sent 1.742 +to 1.743 +.IR sh (1) 1.744 +to be interpreted as a command. 1.745 +.RB ` . ' 1.746 +is unchanged. 1.747 +If the command starts with a 1.748 +.RB ` ! ', 1.749 +the previous command is inserted. 1.750 +A 1.751 +.RB ` % ' 1.752 +causes the current file name to be inserted. 1.753 +.TP 5 1.754 +\fR(\|\fI.+1\fR)\|<newline> 1.755 +An address alone on a line causes the addressed line to be printed. 1.756 +A blank line alone is equivalent to `.+1p'; it is useful 1.757 +for stepping through text. 1.758 +.PP 1.759 +The following commands are extensions: 1.760 +.TP 5 1.761 +\fR(\|\fI.\|\fR)\fB\|b\fR[\fIcount\fR] 1.762 +Prints a screenful of lines, 1.763 +starting at the addressed one, 1.764 +and browses forward in the buffer by this amount. 1.765 +With the optional 1.766 +.I count 1.767 +argument, the screen size for this and following 1.768 +.I b 1.769 +commands is set to the given number of lines. 1.770 +.TP 5 1.771 +.B help 1.772 +Causes a summary of 1.773 +.I ed 1.774 +commands along with short descriptions 1.775 +to be printed on the terminal. 1.776 +.TP 5 1.777 +.B N 1.778 +Makes the 1.779 +.I p 1.780 +command behave like the 1.781 +.I n 1.782 +command and vice-versa. 1.783 +If given a second time, 1.784 +the original semantics are restored. 1.785 +.TP 5 1.786 +\fR(\|\fI.\|\fR)\fB\|o\fR[\fIcount\fR] 1.787 +Prints a screenful of lines centered around the addressed one. 1.788 +The current line is not changed. 1.789 +With the optional 1.790 +.I count 1.791 +argument, the amount of lines printed above and below 1.792 +for this and following 1.793 +.I o 1.794 +commands is set to the given number. 1.795 +.TP 5 1.796 +.B z 1.797 +Performs the same actions as a 1.798 +.I w 1.799 +command followed by a 1.800 +.I q 1.801 +command. 1.802 +.PP 1.803 +If an interrupt signal is sent, 1.804 +.I ed 1.805 +prints a `?' and returns to its command level. 1.806 +.PP 1.807 +An input line that consists exactly of the two characters `\e.' 1.808 +causes a period `.' to be inserted with the 1.809 +.IR a , 1.810 +.IR c , 1.811 +and 1.812 +.IR i 1.813 +commands. 1.814 +.PP 1.815 +Some size limitations: 1.816 +The maximum number of bytes in the buffer 1.817 +corresponds to the address size; 1.818 +on machines with 32-bit addressing, 1.819 +it is 2\ G bytes, 1.820 +with 64-bit addressing, 1.821 +it is 9\ E bytes. 1.822 +The limit on the number of lines depends on the amount of core: 1.823 +each line takes 2 words. 1.824 +.PP 1.825 +If a line contains a NUL character, 1.826 +regular expressions cannot match beyond this character. 1.827 +A substitute command deletes a NUL 1.828 +and all following characters on the line. 1.829 +NUL characters in command input are discarded. 1.830 +If an input file does not end with a newline, 1.831 +.I ed 1.832 +prints a message and appends one. 1.833 +.PP 1.834 +Omission of the `/' character 1.835 +following the regular expression or the replacement string 1.836 +to the global and substitute commands 1.837 +causes the affected lines to be printed. 1.838 +Thus the following commands have the same effect: 1.839 +.RS 1.840 +g/pattern g/pattern/p 1.841 +.br 1.842 +s/pattern/repl s/pattern/repl/p 1.843 +.br 1.844 +s/pattern/ s/pattern//p 1.845 +.RE 1.846 +.SH "ENVIRONMENT VARIABLES" 1.847 +.TP 1.848 +.BR LANG ", " LC_ALL 1.849 +See 1.850 +.IR locale (7). 1.851 +.TP 1.852 +.B LC_CTYPE 1.853 +Determines the mapping of bytes to characters 1.854 +and the set of printable characters for the 1.855 +.I l 1.856 +command. 1.857 +.TP 1.858 +.B TMPDIR 1.859 +Determines the location of the temporary file 1.860 +if it contains the name of an accessible directory. 1.861 +.SH FILES 1.862 +/var/tmp/e* 1.863 +.br 1.864 +/tmp/e* 1.865 +.br 1.866 +ed.hup: work is saved here if terminal hangs up 1.867 +.SH "SEE ALSO" 1.868 +B. W. Kernighan, 1.869 +.I 1.870 +A Tutorial Introduction to the ED Text Editor 1.871 +.br 1.872 +B. W. Kernighan, 1.873 +.I Advanced editing on UNIX 1.874 +.br 1.875 +bfs(1), 1.876 +grep(1), 1.877 +sed(1), 1.878 +sh(1) 1.879 +.SH DIAGNOSTICS 1.880 +`?name' for inaccessible file; 1.881 +`?' for 1.882 +errors in commands, 1.883 +possibly followed by a verbose description 1.884 +(see the description for the 1.885 +.I h 1.886 +and 1.887 +.I H 1.888 +commands above). 1.889 +.PP 1.890 +To protect against throwing away valuable work, 1.891 +a 1.892 +.I q 1.893 +or 1.894 +.I e 1.895 +command is considered to be in error, unless a 1.896 +.I w 1.897 +has occurred since the last buffer change. 1.898 +A second 1.899 +.I q 1.900 +or 1.901 +.I e 1.902 +will be obeyed regardless. 1.903 +.SH NOTES 1.904 +A 1.905 +.I !\& 1.906 +command cannot be subject to a 1.907 +.I g 1.908 +command. 1.909 +.PP 1.910 +The LC_COLLATE variable has currently no effect. 1.911 +Ranges in bracket expressions are ordered 1.912 +as byte values in single-byte locales 1.913 +and as wide character values in multibyte locales. 1.914 +.PP 1.915 +For portable programs, restrict textual data 1.916 +to the US-ASCII character set and 1.917 +set the LC_CTYPE and LC_COLLATE variables to `C' or `POSIX'.