meillo@0: '\" t meillo@0: .\" Sccsid @(#)ed.1 1.48 (gritter) 6/22/05 meillo@0: .\" Parts taken from ed(1), Unix 7th edition: meillo@0: .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. meillo@0: .\" meillo@0: .\" Redistribution and use in source and binary forms, with or without meillo@0: .\" modification, are permitted provided that the following conditions meillo@0: .\" are met: meillo@0: .\" Redistributions of source code and documentation must retain the meillo@0: .\" above copyright notice, this list of conditions and the following meillo@0: .\" disclaimer. meillo@0: .\" Redistributions in binary form must reproduce the above copyright meillo@0: .\" notice, this list of conditions and the following disclaimer in the meillo@0: .\" documentation and/or other materials provided with the distribution. meillo@0: .\" All advertising materials mentioning features or use of this software meillo@0: .\" must display the following acknowledgement: meillo@0: .\" This product includes software developed or owned by Caldera meillo@0: .\" International, Inc. meillo@0: .\" Neither the name of Caldera International, Inc. nor the names of meillo@0: .\" other contributors may be used to endorse or promote products meillo@0: .\" derived from this software without specific prior written permission. meillo@0: .\" meillo@0: .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA meillo@0: .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR meillo@0: .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED meillo@0: .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE meillo@0: .\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE meillo@0: .\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR meillo@0: .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF meillo@0: .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR meillo@0: .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, meillo@0: .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE meillo@0: .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, meillo@0: .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. meillo@0: .TH ED 1 "6/22/05" "Heirloom Toolchest" "User Commands" meillo@0: .if t .ds q \(aa meillo@0: .if n .ds q ' meillo@0: .SH NAME meillo@0: ed \- text editor meillo@0: .SH SYNOPSIS meillo@0: \fBed\fR [\fB\-\fR\ |\ \fB\-s\fR] [\fB\-p\fI\ prompt\fR] [\fIname\fR] meillo@0: .SH DESCRIPTION meillo@0: .I Ed meillo@0: is the standard text editor. meillo@0: .PP meillo@0: If a meillo@0: .I name meillo@0: argument is given, meillo@0: .I ed meillo@0: simulates an meillo@0: .I e meillo@0: command (see below)\| on the named file; that is to say, meillo@0: the file is read into meillo@0: .IR ed 's meillo@0: buffer so that it can be edited. meillo@0: The optional meillo@0: .B \- meillo@0: or meillo@0: .B \-s meillo@0: suppresses the printing meillo@0: of character counts by meillo@0: .IR e , meillo@0: .IR r , meillo@0: and meillo@0: .I w meillo@0: commands, meillo@0: and of the `!' after completion of a shell command. meillo@0: .PP meillo@0: With the meillo@0: .B \-p meillo@0: option, meillo@0: the given meillo@0: .I prompt meillo@0: string is printed before each command is read. meillo@0: .PP meillo@0: .I Ed meillo@0: operates on a copy of any file it is editing; changes made meillo@0: in the copy have no effect on the file until a meillo@0: .IR w "" meillo@0: (write)\| meillo@0: command is given. meillo@0: The copy of the text being edited resides meillo@0: in a temporary file called the meillo@0: .IR buffer . meillo@0: .PP meillo@0: The editor supports format specifications as defined in meillo@0: .IR fspec (5). meillo@0: If the terminal is configured to expand tabulators meillo@0: (as enabled with meillo@0: .I stty tab3 meillo@0: or meillo@0: .IR "stty \-tabs"), meillo@0: and the first line of the file being edited meillo@0: contains a format specification, meillo@0: the meillo@0: .I t meillo@0: and meillo@0: .I s meillo@0: are interpreted, meillo@0: that is, tabulators are expanded and lines are truncated meillo@0: when printing to the terminal. For example, meillo@0: .RS meillo@0: <:t\-f s72:> meillo@0: .sp meillo@0: .RE meillo@0: selects FORTRAN format and truncates lines at 72 characters. meillo@0: No expansion or truncation is performed by meillo@0: .I ed meillo@0: when input is typed to the terminal. meillo@0: .PP meillo@0: Commands to meillo@0: .I ed meillo@0: have a simple and regular structure: zero or meillo@0: more meillo@0: .I addresses meillo@0: followed by a single character meillo@0: .I command, meillo@0: possibly meillo@0: followed by parameters to the command. meillo@0: These addresses specify one or more lines in the buffer. meillo@0: Missing addresses are supplied by default. meillo@0: .PP meillo@0: In general, only one command may appear on a line. meillo@0: Certain commands allow the meillo@0: addition of text to the buffer. meillo@0: While meillo@0: .I ed meillo@0: is accepting text, it is said meillo@0: to be in meillo@0: .I "input mode." meillo@0: In this mode, no commands are recognized; meillo@0: all input is merely collected. meillo@0: Input mode is left by typing a period `\fB.\fR' alone at the meillo@0: beginning of a line. meillo@0: .PP meillo@0: .I Ed meillo@0: supports a limited form of meillo@0: .I "regular expression" meillo@0: notation. meillo@0: A regular expression specifies meillo@0: a set of strings of characters. meillo@0: A member of this set of strings is said to be meillo@0: .I matched meillo@0: by the regular expression. meillo@0: In the following specification for regular expressions meillo@0: the word `character' means any character but newline. meillo@0: .B ed meillo@0: uses simple regular expressions. meillo@0: .SS "Simple Regular Expressions" meillo@0: .IP 1. meillo@0: Any character except a special character meillo@0: matches itself. meillo@0: Special characters are meillo@0: the regular expression delimiter plus meillo@0: .RB \e\|[\| . meillo@0: and sometimes ^\|*\|$. meillo@0: .IP 2. meillo@0: A meillo@0: .B .\& meillo@0: matches any character. meillo@0: .IP 3. meillo@0: A \fB\e\fR followed by any character except a digit meillo@0: or (\|) {\|} <\|> matches that character. meillo@0: .IP 4. meillo@0: A nonempty string meillo@0: .I s meillo@0: bracketed meillo@0: \fB[\fI\|s\|\fB]\fR meillo@0: (or meillo@0: \fB[^\fIs\|\fB]\fR) meillo@0: forms a \fIbracket expression\fR that meillo@0: matches any character in (or not in) meillo@0: .I s. meillo@0: In meillo@0: .I s, meillo@0: \e has no special meaning, and ] may only appear as meillo@0: the first letter. meillo@0: A substring meillo@0: \fIa\fB\-\fIb\fR, meillo@0: with meillo@0: .I a meillo@0: and meillo@0: .I b meillo@0: in ascending ASCII order, stands for the inclusive meillo@0: range of ASCII characters. meillo@0: .IP 5. meillo@0: A regular expression of form 1-4 followed by \fB*\fR matches a sequence of meillo@0: 0 or more matches of the regular expression. meillo@0: .IP 6. meillo@0: A regular expression of form 1-4 meillo@0: followed by \fB\e{\fIm\fB,\fIn\fB\e}\fR meillo@0: forms an \fIinterval expression\fR that meillo@0: matches a sequence of \fIm\fR through \fIn\fR matches, inclusive, meillo@0: of the regular expression. meillo@0: The values of \fIm\fR and \fIn\fR must be non-negative meillo@0: and smaller than 256. meillo@0: The form \fB\e{\fIm\fB\e}\fR matches exactly \fIm\fR occurrences, meillo@0: \fB\e{\fIm\fB,\e}\fR matches at least \fIm\fR occurrences. meillo@0: .IP 7. meillo@0: The sequence \fB\e<\fR forces the match meillo@0: to occur only at the beginning of a ``variable'' or ``word''; meillo@0: that is, either at the beginning of a line, meillo@0: or just before a letter, digit or underline meillo@0: and after a character not one of these. meillo@0: .IP 8. meillo@0: The sequence \fB\e>\fR matches the end meillo@0: of a ``variable'' or ``word'', meillo@0: i.\|e. either the end of the line meillo@0: or before character which is neither a letter, meillo@0: nor a digit, nor the underline character. meillo@0: .IP 9. meillo@0: A regular expression, meillo@0: .I x, meillo@0: of form 1-11, parenthesized meillo@0: \fB\e(\fI\|x\|\fB\e)\fR meillo@0: is called a \fIsubexpression\fR and meillo@0: matches what meillo@0: .I x meillo@0: matches. meillo@0: .IP 10. meillo@0: A \fB\e\fR followed by a digit meillo@0: .I n meillo@0: forms a \fIbackreference\fR and meillo@0: matches a copy of the string that the meillo@0: parenthesized regular expression beginning with the meillo@0: .IR n th meillo@0: \e( matched. meillo@0: .IP 11. meillo@0: A regular expression of form 1-11, meillo@0: .I x, meillo@0: followed by a regular expression of form 1-10, meillo@0: .I y meillo@0: matches a match for meillo@0: .I x meillo@0: followed by a match for meillo@0: .I y, meillo@0: with the meillo@0: .I x meillo@0: match being as long as possible while still permitting a meillo@0: .I y meillo@0: match. meillo@0: .IP 12. meillo@0: A regular expression of form 1-11 preceded by \fB^\fR meillo@0: (or followed by \fB$\fR), is constrained to matches that meillo@0: begin at the left (or end at the right) end of a line meillo@0: (\fIanchoring\fR). meillo@0: .IP 13. meillo@0: A regular expression of form 1-12 picks out the meillo@0: longest among the leftmost matches in a line. meillo@0: .IP 14. meillo@0: An empty regular expression stands for a copy of the meillo@0: last regular expression encountered. meillo@0: .PP meillo@0: Regular expressions are used in addresses to specify meillo@0: lines and in one command meillo@0: (see meillo@0: .I s meillo@0: below)\| meillo@0: to specify a portion of a line which is to be replaced. meillo@0: If it is desired to use one of meillo@0: the regular expression metacharacters as an ordinary meillo@0: character, that character may be preceded by `\e'. meillo@0: This also applies to the character bounding the regular meillo@0: expression (often `/')\| and to `\e' itself. meillo@0: .PP meillo@0: To understand addressing in meillo@0: .I ed meillo@0: it is necessary to know that at any time there is a meillo@0: .I "current line." meillo@0: Generally speaking, the current line is meillo@0: the last line affected by a command; however, meillo@0: the exact effect on the current line meillo@0: is discussed under the description of meillo@0: the command. meillo@0: Addresses are constructed as follows. meillo@0: .TP meillo@0: 1. meillo@0: The character `\fB.\fR' addresses the current line. meillo@0: .TP meillo@0: 2. meillo@0: The character `\fB$\fR' addresses the last line of the buffer. meillo@0: .TP meillo@0: 3. meillo@0: A decimal number meillo@0: .I n meillo@0: addresses the meillo@0: .IR n -th meillo@0: line of the buffer. meillo@0: .TP meillo@0: 4. meillo@0: `\fB\(fm\fIx\fR' addresses the line marked with the name meillo@0: .IR x , meillo@0: which must be a lower-case letter. meillo@0: Lines are marked with the meillo@0: .I k meillo@0: command described below. meillo@0: .TP meillo@0: 5. meillo@0: A regular expression enclosed in slashes `\fB/\fR' addresses meillo@0: the line found by searching forward from the current line meillo@0: and stopping at the first line containing a meillo@0: string that matches the regular expression. meillo@0: If necessary the search wraps around to the beginning of the meillo@0: buffer. meillo@0: .TP meillo@0: 6. meillo@0: A regular expression enclosed in queries `\fB?\fR' addresses meillo@0: the line found by searching backward from the current line meillo@0: and stopping at the first line containing meillo@0: a string that matches the regular expression. meillo@0: If necessary meillo@0: the search wraps around to the end of the buffer. meillo@0: .TP meillo@0: 7. meillo@0: An address followed by a plus sign `\fB+\fR' meillo@0: or a minus sign `\fB\-\fR' followed by a decimal number meillo@0: specifies that address plus meillo@0: (resp. minus)\| the indicated number of lines. meillo@0: The plus sign may be omitted. meillo@0: .TP meillo@0: 8. meillo@0: If an address begins with `\fB+\fR' or `\fB\-\fR' meillo@0: the addition or subtraction is taken with respect to the current line; meillo@0: e.g. `\-5' is understood to mean `\fB.\fR\-5'. meillo@0: .TP meillo@0: 9. meillo@0: If an address ends with `\fB+\fR' or `\fB\-\fR', meillo@0: then 1 is added (resp. subtracted). meillo@0: As a consequence of this rule and rule 8, meillo@0: the address `\-' refers to the line before the current line. meillo@0: Moreover, meillo@0: trailing meillo@0: `+' and `\-' characters meillo@0: have cumulative effect, so `\-\-' refers to the current meillo@0: line less 2. meillo@0: .TP meillo@0: 10. meillo@0: To maintain compatibility with earlier versions of the editor, meillo@0: the character `\fB^\fR' in addresses is meillo@0: equivalent to `\-'. meillo@0: .PP meillo@0: Commands may require zero, one, or two addresses. meillo@0: Commands which require no addresses regard the presence meillo@0: of an address as an error. meillo@0: Commands which accept one or two addresses meillo@0: assume default addresses when insufficient are given. meillo@0: If more addresses are given than such a command requires, meillo@0: the last one or two (depending on what is accepted)\| are used. meillo@0: .PP meillo@0: Addresses are separated from each other typically by a comma meillo@0: `\fB,\fR'. meillo@0: They may also be separated by a semicolon meillo@0: `\fB;\fR'. meillo@0: In this case the current line `\fB.\fR' is set to meillo@0: the previous address before the next address is interpreted. meillo@0: This feature can be used to determine the starting meillo@0: line for forward and backward searches (`/', `?')\|. meillo@0: The second address of any two-address sequence meillo@0: must correspond to a line following the line corresponding to the first address. meillo@0: .PP meillo@0: Omission of the first address causes meillo@0: the first line to be used with `,', meillo@0: or the current line with `;', respectively; meillo@0: if the second address is also omitted, meillo@0: the last line of the buffer is used. meillo@0: Thus a single `,' specifies the entire contents of the buffer, meillo@0: and a single `;' specifies the contents meillo@0: ranging from the current line to the last one. meillo@0: .PP meillo@0: In the following list of meillo@0: .I ed meillo@0: commands, the default addresses meillo@0: are shown in parentheses. meillo@0: The parentheses are not part of meillo@0: the address, but are used to show that the given addresses are meillo@0: the default. meillo@0: .PP meillo@0: As mentioned, it is generally illegal for more than one meillo@0: command to appear on a line. meillo@0: However, most commands may be suffixed by `p', `l', or `n', meillo@0: in which case meillo@0: the current line is either meillo@0: printed, listed, or numbered respectively meillo@0: in the way discussed below. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fR)\fB\|a\fR meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: .B . meillo@0: .br meillo@0: The append command reads the given text meillo@0: and appends it after the addressed line. meillo@0: `\fB.\fR' is left meillo@0: on the last line input, if there meillo@0: were any, otherwise at the addressed line. meillo@0: Address `0' is legal for this command; text is placed meillo@0: at the beginning of the buffer. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBc\fR meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: .B . meillo@0: .br meillo@0: The change meillo@0: command deletes the addressed lines, then accepts input meillo@0: text which replaces these lines. meillo@0: `\fB.\fR' is left at the last line input; if there were none, meillo@0: it is left at the line preceding the deleted lines. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBd\fR meillo@0: The delete command deletes the addressed lines from the buffer. meillo@0: The line originally after the last line deleted becomes the current line; meillo@0: if the lines deleted were originally at the end, meillo@0: the new last line becomes the current line. meillo@0: .TP 5 meillo@0: \fBe\ \fIfilename\fR meillo@0: The edit meillo@0: command causes the entire contents of the buffer to be deleted, meillo@0: and then the named file to be read in. meillo@0: `\fB.\fR' is set to the last line of the buffer. meillo@0: The number of characters read is typed. meillo@0: `\fIfilename\fR' is remembered for possible use as a default file name meillo@0: in a subsequent meillo@0: .I r meillo@0: or meillo@0: .I w meillo@0: command. meillo@0: If `\fIfilename\fR' is missing, the remembered name is used. meillo@0: A `\fIfilename\fR' starting with a `\fB!\fR' meillo@0: causes the output of the shell command following this character meillo@0: to be read in. meillo@0: .TP 5 meillo@0: \fBE\ \fIfilename\fR meillo@0: This command is the same as meillo@0: .IR e , meillo@0: except that no diagnostic results when no meillo@0: .I w meillo@0: has been given since the last buffer alteration. meillo@0: .TP 5 meillo@0: \fBf\ \fIfilename\fR meillo@0: The filename command prints the currently remembered file name. meillo@0: If `\fIfilename\fR' is given, meillo@0: the currently remembered file name is changed to `\fIfilename\fR'. meillo@0: .TP 5 meillo@0: \fR(\fI1\fB,\fI$\fR)\|\fBg/\fIregular expression\fB/\fIcommand list\fR meillo@0: In the global meillo@0: command, the first step is to mark every line which matches meillo@0: the given \fIregular expression\fR. meillo@0: Then for every such line, the meillo@0: given \fIcommand list\fR is executed meillo@0: with `\fB.\fR' initially set to that line. meillo@0: A single command or the first of multiple commands meillo@0: appears on the same line with the global command. meillo@0: All lines of a multi-line list except the last line must be ended with `\e'. meillo@0: .I A, meillo@0: .I i, meillo@0: and meillo@0: .I c meillo@0: commands and associated input are permitted; meillo@0: the `\fB.\fR' terminating input mode may be omitted if it would be on the meillo@0: last line of the command list. meillo@0: The commands meillo@0: .I g meillo@0: and meillo@0: .I v meillo@0: are not permitted in the command list. meillo@0: .TP 5 meillo@0: \fR(\fI1\fB,\fI$\fR)\|\fBG/\fIregular expression\fB/\fR meillo@0: The interactive global command meillo@0: first marks every line matching the given \fIregular expression\fR. meillo@0: Then each line is printed meillo@0: and a command is read and executed for this line. meillo@0: A single newline character causes the line to remain unchanged, meillo@0: an isolated `\fB&\fR' repeats the command given for the previous line. meillo@0: The command can be terminated by an interrupt signal. meillo@0: .TP 5 meillo@0: .B h meillo@0: This command prints a verbose description for the meillo@0: last error encountered. meillo@0: .TP meillo@0: .B H meillo@0: This command acts like the meillo@0: .I h meillo@0: command, meillo@0: but also causes verbose descriptions to be printed meillo@0: on all following error conditions. meillo@0: Another meillo@0: .I H meillo@0: turns verbose mode off. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fR)\|\fBi\fR meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: .B . meillo@0: .br meillo@0: This command inserts the given text before the addressed line. meillo@0: `\fB.\fR' is left at the last line input, or, if there were none, meillo@0: at the line before the addressed line. meillo@0: This command differs from the meillo@0: .I a meillo@0: command only in the placement of the meillo@0: text. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.+1\fR)\|\fBj\fR meillo@0: This command joins the addressed lines into a single line; meillo@0: intermediate newlines simply disappear. meillo@0: `\fB.\fR' is left at the resulting line. meillo@0: .TP 5 meillo@0: \fR(\fI.\fR)\|\fBk\fIx\fR meillo@0: The mark command marks the addressed line with meillo@0: name meillo@0: .IR x , meillo@0: which must be a lower-case letter. meillo@0: The address form `\(fm\fIx\fR' then addresses this line. meillo@0: .ne 2.5 meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBl\fR meillo@0: The list command meillo@0: prints the addressed lines in an unambiguous way: meillo@0: non-graphic control characters are printed in three-digit octal; meillo@0: Long lines are folded. meillo@0: The meillo@0: .I l meillo@0: command may be placed on the same line after any non-i/o meillo@0: command. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBm\fIa\fR meillo@0: The move command repositions the addressed lines after the line meillo@0: addressed by meillo@0: .IR a . meillo@0: The last of the moved lines becomes the current line. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBn\fR meillo@0: This command prints lines preceded by their line numbers. meillo@0: It otherwise acts like the meillo@0: .I p meillo@0: command described below. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBp\fR meillo@0: The print command prints the addressed lines. meillo@0: `\fB.\fR' meillo@0: is left at the last line printed. meillo@0: The meillo@0: .I p meillo@0: command meillo@0: may meillo@0: be placed on the same line after any non-i/o command. meillo@0: .TP meillo@0: .B P meillo@0: This command causes a prompt to be printed meillo@0: before following commands are read. meillo@0: The default prompt is a `*' character, meillo@0: but can be set with the meillo@0: .I \-p meillo@0: command line option (which also enables the prompt). meillo@0: Another meillo@0: .I P meillo@0: disables the prompt. meillo@0: .TP 5 meillo@0: .B q meillo@0: The quit command causes meillo@0: .I ed meillo@0: to exit. meillo@0: No automatic write meillo@0: of a file is done. meillo@0: .TP 5 meillo@0: .B Q meillo@0: This command is the same as meillo@0: .I q, meillo@0: except that no diagnostic results when no meillo@0: .I w meillo@0: has been given since the last buffer alteration. meillo@0: .TP 5 meillo@0: \fR(\fI$\fR)\|\fBr\ \fIfilename\fR meillo@0: The read command meillo@0: reads in the given file after the addressed line. meillo@0: If no file name is given, meillo@0: the remembered file name, if any, is used meillo@0: (see meillo@0: .I e meillo@0: and meillo@0: .I f meillo@0: commands)\|. meillo@0: The file name is remembered if there was no meillo@0: remembered file name already. meillo@0: Address `0' is legal for meillo@0: .I r meillo@0: and causes the meillo@0: file to be read at the beginning of the buffer. meillo@0: If the read is successful, the number of characters meillo@0: read is typed. meillo@0: `\fB.\fR' is left at the last line read in from the file. meillo@0: A `filename' starting with a `\fB!\fR' meillo@0: causes the output of the shell command following this character meillo@0: to be read in. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fR or, meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/g\fR or, meillo@0: .br meillo@0: .ns meillo@0: .TP 5 meillo@0: \fR(\|\fI.\fB\|,\|\fI.\fR\|)\|\fBs/\fIregular expression\fB/\fIreplacement\fB/\fInumber\fR meillo@0: The substitute command searches each addressed meillo@0: line for an occurrence of the specified regular expression. meillo@0: On each line in which a match is found, meillo@0: all matched strings are replaced by the replacement specified, meillo@0: if the global replacement indicator meillo@0: .RB ` g ' meillo@0: appears after the command. meillo@0: If the global indicator does not appear, only the first occurrence meillo@0: of the matched string is replaced; meillo@0: if the \fInumber\fR indicator is given, meillo@0: the numbered occurrence is replaced. meillo@0: It is an error for the substitution to fail on all addressed lines. meillo@0: Any character other than space or new-line meillo@0: may be used instead of `/' to delimit the regular expression meillo@0: and the replacement. meillo@0: `\fB.\fR' is left at the last line substituted. meillo@0: .IP meillo@0: An ampersand meillo@0: .RB ` & ' meillo@0: appearing in the replacement meillo@0: is replaced by the string matching the regular expression. meillo@0: The special meaning of `&' in this context may be meillo@0: suppressed by preceding it by meillo@0: .RB ` \e '. meillo@0: The characters `\|\fB\e\fIn\fR' meillo@0: where meillo@0: .I n meillo@0: is a digit, meillo@0: are replaced by the text matched by the meillo@0: .IR n -th meillo@0: regular subexpression meillo@0: enclosed between `\e(' and `\e)'. meillo@0: When meillo@0: nested, parenthesized subexpressions meillo@0: are present, meillo@0: .I n meillo@0: is determined by counting occurrences of `\e(' starting from the left. meillo@0: .IP meillo@0: A substitution string consisting of a single meillo@0: .RB ` % ' meillo@0: causes the string given on the previous substitution to be re-used. meillo@0: .IP meillo@0: Lines may be split by substituting new-line characters into them. meillo@0: The new-line in the meillo@0: replacement string meillo@0: must be escaped by preceding it by meillo@0: .RB ` \e '. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fB,\|\fI.\|\fR)\|\fBt\|\fIa\fR meillo@0: This command acts just like the meillo@0: .I m meillo@0: command, except that a copy of the addressed lines is placed meillo@0: after address meillo@0: .I a meillo@0: (which may be 0). meillo@0: `\fB.\fR' is left on the last line of the copy. meillo@0: .TP 5 meillo@0: .B u meillo@0: The undo command restores meillo@0: the contents of the buffer meillo@0: before the last command was executed. meillo@0: If the undo command is given twice, meillo@0: the current state is restored. meillo@0: .TP 5 meillo@0: \fR(\fI1\fB,\fI$\fR)\|\fBv/\fIregular expression\fB/\fIcommand list\fR meillo@0: This command is the same as the global command meillo@0: .I g meillo@0: except that the command list is executed meillo@0: .I g meillo@0: with `\fB.\fR' initially set to every line meillo@0: .I except meillo@0: those meillo@0: matching the regular expression. meillo@0: .TP 5 meillo@0: \fR(\fI1\fB,\fI$\fR)\|\fBV/\fIregular expression\fB/\fR meillo@0: This command is the same as the interactive global command meillo@0: .I G meillo@0: except that the commands are read meillo@0: .I g meillo@0: with `\fB.\fR' initially set to every line meillo@0: .I except meillo@0: those meillo@0: matching the regular expression. meillo@0: .TP 5 meillo@0: \fR(\fI1\fB,\fI$\fR)\|\fBw\ \fIfilename\fR meillo@0: .br meillo@0: The write command writes the addressed lines onto meillo@0: the given file. meillo@0: If the file does not exist, meillo@0: it is created mode 666 (readable and writable by everyone)\|. meillo@0: The file name is remembered if there was no meillo@0: remembered file name already. meillo@0: If no file name is given, meillo@0: the remembered file name, if any, is used meillo@0: (see meillo@0: .I e meillo@0: and meillo@0: .I f meillo@0: commands)\|. meillo@0: `\fB.\fR' is unchanged. meillo@0: If the command is successful, the number of characters written is meillo@0: printed. meillo@0: A `filename' starting with a `\fB!\fR' meillo@0: causes the string following this character meillo@0: to be executed as a shell command meillo@0: with the addressed lines as standard input. meillo@0: .TP meillo@0: \fR(\fI1\fB,\fI$\fR)\fBW\ \fIfilename\fR meillo@0: This command is the same as meillo@0: .I w, meillo@0: except that the addressed lines are appended to the file. meillo@0: .TP 5 meillo@0: \fR(\fI$\fR)\|\fB=\fR meillo@0: The line number of the addressed line is typed. meillo@0: `\fB.\fR' is unchanged by this command. meillo@0: .TP 5 meillo@0: \fB!\fR meillo@0: The remainder of the line after the `!' is sent meillo@0: to meillo@0: .IR sh (1) meillo@0: to be interpreted as a command. meillo@0: .RB ` . ' meillo@0: is unchanged. meillo@0: If the command starts with a meillo@0: .RB ` ! ', meillo@0: the previous command is inserted. meillo@0: A meillo@0: .RB ` % ' meillo@0: causes the current file name to be inserted. meillo@0: .TP 5 meillo@0: \fR(\|\fI.+1\fR)\| meillo@0: An address alone on a line causes the addressed line to be printed. meillo@0: A blank line alone is equivalent to `.+1p'; it is useful meillo@0: for stepping through text. meillo@0: .PP meillo@0: The following commands are extensions: meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fR)\fB\|b\fR[\fIcount\fR] meillo@0: Prints a screenful of lines, meillo@0: starting at the addressed one, meillo@0: and browses forward in the buffer by this amount. meillo@0: With the optional meillo@0: .I count meillo@0: argument, the screen size for this and following meillo@0: .I b meillo@0: commands is set to the given number of lines. meillo@0: .TP 5 meillo@0: .B help meillo@0: Causes a summary of meillo@0: .I ed meillo@0: commands along with short descriptions meillo@0: to be printed on the terminal. meillo@0: .TP 5 meillo@0: .B N meillo@0: Makes the meillo@0: .I p meillo@0: command behave like the meillo@0: .I n meillo@0: command and vice-versa. meillo@0: If given a second time, meillo@0: the original semantics are restored. meillo@0: .TP 5 meillo@0: \fR(\|\fI.\|\fR)\fB\|o\fR[\fIcount\fR] meillo@0: Prints a screenful of lines centered around the addressed one. meillo@0: The current line is not changed. meillo@0: With the optional meillo@0: .I count meillo@0: argument, the amount of lines printed above and below meillo@0: for this and following meillo@0: .I o meillo@0: commands is set to the given number. meillo@0: .TP 5 meillo@0: .B z meillo@0: Performs the same actions as a meillo@0: .I w meillo@0: command followed by a meillo@0: .I q meillo@0: command. meillo@0: .PP meillo@0: If an interrupt signal is sent, meillo@0: .I ed meillo@0: prints a `?' and returns to its command level. meillo@0: .PP meillo@0: An input line that consists exactly of the two characters `\e.' meillo@0: causes a period `.' to be inserted with the meillo@0: .IR a , meillo@0: .IR c , meillo@0: and meillo@0: .IR i meillo@0: commands. meillo@0: .PP meillo@0: Some size limitations: meillo@0: The maximum number of bytes in the buffer meillo@0: corresponds to the address size; meillo@0: on machines with 32-bit addressing, meillo@0: it is 2\ G bytes, meillo@0: with 64-bit addressing, meillo@0: it is 9\ E bytes. meillo@0: The limit on the number of lines depends on the amount of core: meillo@0: each line takes 2 words. meillo@0: .PP meillo@0: If a line contains a NUL character, meillo@0: regular expressions cannot match beyond this character. meillo@0: A substitute command deletes a NUL meillo@0: and all following characters on the line. meillo@0: NUL characters in command input are discarded. meillo@0: If an input file does not end with a newline, meillo@0: .I ed meillo@0: prints a message and appends one. meillo@0: .PP meillo@0: Omission of the `/' character meillo@0: following the regular expression or the replacement string meillo@0: to the global and substitute commands meillo@0: causes the affected lines to be printed. meillo@0: Thus the following commands have the same effect: meillo@0: .RS meillo@0: g/pattern g/pattern/p meillo@0: .br meillo@0: s/pattern/repl s/pattern/repl/p meillo@0: .br meillo@0: s/pattern/ s/pattern//p meillo@0: .RE meillo@0: .SH "ENVIRONMENT VARIABLES" meillo@0: .TP meillo@0: .BR LANG ", " LC_ALL meillo@0: See meillo@0: .IR locale (7). meillo@0: .TP meillo@0: .B LC_CTYPE meillo@0: Determines the mapping of bytes to characters meillo@0: and the set of printable characters for the meillo@0: .I l meillo@0: command. meillo@0: .TP meillo@0: .B TMPDIR meillo@0: Determines the location of the temporary file meillo@0: if it contains the name of an accessible directory. meillo@0: .SH FILES meillo@0: /var/tmp/e* meillo@0: .br meillo@0: /tmp/e* meillo@0: .br meillo@0: ed.hup: work is saved here if terminal hangs up meillo@0: .SH "SEE ALSO" meillo@0: B. W. Kernighan, meillo@0: .I meillo@0: A Tutorial Introduction to the ED Text Editor meillo@0: .br meillo@0: B. W. Kernighan, meillo@0: .I Advanced editing on UNIX meillo@0: .br meillo@0: bfs(1), meillo@0: grep(1), meillo@0: sed(1), meillo@0: sh(1) meillo@0: .SH DIAGNOSTICS meillo@0: `?name' for inaccessible file; meillo@0: `?' for meillo@0: errors in commands, meillo@0: possibly followed by a verbose description meillo@0: (see the description for the meillo@0: .I h meillo@0: and meillo@0: .I H meillo@0: commands above). meillo@0: .PP meillo@0: To protect against throwing away valuable work, meillo@0: a meillo@0: .I q meillo@0: or meillo@0: .I e meillo@0: command is considered to be in error, unless a meillo@0: .I w meillo@0: has occurred since the last buffer change. meillo@0: A second meillo@0: .I q meillo@0: or meillo@0: .I e meillo@0: will be obeyed regardless. meillo@0: .SH NOTES meillo@0: A meillo@0: .I !\& meillo@0: command cannot be subject to a meillo@0: .I g meillo@0: command. meillo@0: .PP meillo@0: The LC_COLLATE variable has currently no effect. meillo@0: Ranges in bracket expressions are ordered meillo@0: as byte values in single-byte locales meillo@0: and as wide character values in multibyte locales. meillo@0: .PP meillo@0: For portable programs, restrict textual data meillo@0: to the US-ASCII character set and meillo@0: set the LC_CTYPE and LC_COLLATE variables to `C' or `POSIX'.