.\" $OpenBSD: t11.1,v 1.2 2007/11/27 16:22:12 martynas Exp $.\" $NetBSD: ed.1,v 1.13 1995/03/21 09:04:38 cgd Exp $.\".TH ED 1 "21 May 1993".SH NAME.\" ed, red \- text editored \- text editor.SH SYNOPSISed [-] [-sx] [-p \fIstring\fR] [\fIfile\fR].\" .LP.\" red [-] [-sx] [-p \fIstring\fR] [\fIfile\fR].SH DESCRIPTION.B edis a line-oriented text editor.It is used to create, display, modify and otherwise manipulate textfiles..\" .B red.\" is a restricted.\" .BR ed :.\" it can only edit files in the current.\" directory and cannot execute shell commands. If invoked with a.I fileargument, then a copy of.I fileis read into the editor's buffer.Changes are made to this copy and not directly to.I fileitself.Upon quitting.BR ed ,any changes not explicitly saved with a.I `w'command are lost. Editing is done in two distinct modes:.I commandand.IR input .When first invoked,.B edis in command mode.In this mode commands are read from the standard input andexecuted to manipulate the contents of the editor buffer.A typical command might look like:.sp.RS,s/\fIold\fR/\fInew\fR/g.RE.spwhich replaces all occurrences of the string.I oldwith.IR new . When an input command, such as.I `a'(append),.I `i'(insert) or.I `c'(change), is given,.B edenters input mode. This is the primary meansof adding text to a file.In this mode, no commands are available;instead, the standard input is writtendirectly to the editor buffer. Lines consist of text up to andincluding a.IR newlinecharacter.Input mode is terminated byentering a single period (\fI.\fR) on a line. All.B edcommands operate on whole lines or ranges of lines; e.g.,the.I `d'command deletes lines; the.I `m'command moves lines, and so on.It is possible to modify only a portion of a line by means of replacement,as in the example above. However even here, the.I `s'command is applied to whole lines at a time. In general,.B edcommands consist of zero or more line addresses, followed by a singlecharacter command and possibly additional parameters; i.e.,commands have the structure:.sp.RS.I [address [,address]]command[parameters].RE.spThe address(es) indicate the line or range of lines to be affected by thecommand. If fewer addresses are given than the command accepts, thendefault addresses are supplied. .SS OPTIONS.TP 8-sSuppresses diagnostics. This should be used if.BR ed 'sstandard input is from a script. .TP 8-xPrompts for an encryption key to be used in subsequent reads and writes(see the.I `x'command). .TP 8.RI \-p \ stringSpecifies a command prompt. This may be toggled on and off with the.I `P'command. .TP 8.I fileSpecifies the name of a file to read. If.I fileis prefixed with abang (!), then it is interpreted as a shell command. In this case,what is read isthe standard output of.I fileexecuted via.IR sh (1).To read a file whose name begins with a bang, prefix thename with a backslash (\\).The default filename is set to.I fileonly if it is not prefixed with a bang. .SS LINE ADDRESSINGAn address represents the number of a line in the buffer..B edmaintains a.I current addresswhich istypically supplied to commands as the default address when none is specified.When a file is first read, the current address is set to the last lineof the file. In general, the current address is set to the last lineaffected by a command. A line address isconstructed from one of the bases in the list below, optionally followedby a numeric offset. The offset may include any combinationof digits, operators (i.e.,.IR + ,.I -and.IR ^ )and whitespace.Addresses are read from left to right, and their values are computedrelative to the current address. One exception to the rule that addresses represent line numbers is theaddress.I 0(zero).This means "before the first line,"and is legal wherever it makes sense. An address range is two addresses separated either by a comma orsemi-colon. The value of the first address in a range cannot exceed thevalue of the second. If only one address is given in a range, thenthe second address is set to the given address. If an.IR n- tupleof addresses is given where.I n > 2,then the corresponding range is determined by the last two addresses inthe.IR n- tuple.If only one address is expected, then the last address is used. Each address in a comma-delimited range is interpreted relative to thecurrent address. In a semi-colon-delimited range, the first address isused to set the current address, and the second address is interpretedrelative to the first. The following address symbols are recognized. .TP 8\&.The current line (address) in the buffer. .TP 8$The last line in the buffer. .TP 8nThe.IR n th,line in the bufferwhere.I nis a number in the range.I [0,$]. .TP 8- or ^The previous line.This is equivalent to.I -1and may be repeated with cumulative effect. .TP 8-\fIn\fR or ^\fIn\fRThe.IR n thprevious line, where.I nis a non-negative number. .TP 8+Thenext line.This is equivalent to.I +1and may be repeated with cumulative effect. .TP 8+\fIn\fR or whitespace\fIn\fRThe.IR n thnext line, where.I nis a non-negative number..I whitespacefollowed by a number.I nis interpreted as.IR +n . .TP 8, \fRor\fB %The first through last lines in the buffer. This is equivalent tothe address range.I 1,$. .TP 8;Thecurrent through last lines in the buffer. This is equivalent tothe address range.I .,$. .TP 8.RI / re/Thenext line containing the regular expression.IR re .The search wraps to the beginning of the buffer and continues down to thecurrent line, if necessary.// repeats the last search. .TP 8.RI ? re?Theprevious line containing the regular expression.IR re .The search wraps to the end of the buffer and continues up to thecurrent line, if necessary.?? repeats the last search. .TP 8.RI \' lcTheline previously marked by a.I `k'(mark) command, where.I lcis a lower case letter. .SS REGULAR EXPRESSIONSRegular expressions are patterns used in selecting text.For example, the.B edcommand.sp.RSg/\fIstring\fR/.RE.spprints all lines containing.IR string .Regular expressions are alsoused by the.I `s'command for selecting old text to be replaced with new. In addition to a specifying string literals, regular expressions canrepresentclasses of strings. Strings thus represented are said to be matchedby the corresponding regular expression.If it is possible for a regular expressionto match several strings in a line, then the left-most longest match isthe one selected. The following symbols are used in constructing regular expressions: .TP 8cAny character.I cnot listed below, including `{', '}', `(', `)', `<' and `>',matches itself. .TP 8\fR\e\fIc\fRAny backslash-escaped character.IR c ,except for `{', '}', `(', `)', `<' and `>',matches itself. .TP 8\fR.\fRMatches any single character. .TP 8.I [char-class]Matches any single character in.IR char-class .To include a `]'in.IR char-class ,it must be the first character.A range of characters may be specified by separating the end charactersof the range with a `-', e.g., `a-z' specifies the lower case characters.The following literal expressions can also be used in.I char-classto specify sets of characters:.sp\ \ [:alnum:]\ \ [:cntrl:]\ \ [:lower:]\ \ [:space:].PD 0\ \ [:alpha:]\ \ [:digit:]\ \ [:print:]\ \ [:upper:].PD 0\ \ [:blank:]\ \ [:graph:]\ \ [:punct:]\ \ [:xdigit:].spIf `-' appears as the first or lastcharacter of.IR char-class ,then it matches itself.All other characters in.I char-classmatch themselves..spPatterns in.I char-classof the form:.sp\ \ [.\fIcol-elm\fR.] or,.PD 0\ \ [=\fIcol-elm\fR=].spwhere.I col-elmis a.I collating elementare interpreted according to.IR locale (5)(not currently supported).See.IR regex (3)for an explanation of these constructs. .TP 8[^\fIchar-class\fR]Matches any single character, other than newline, not in.IR char-class ..IR char-classis definedas above. .TP 8^If `^' is the first character of a regular expression, then itanchors the regular expression to the beginning of a line.Otherwise, it matches itself. .TP 8$If `$' is the last character of a regular expression, itanchors the regular expression to the end of a line.Otherwise, it matches itself. .TP 8\fR\e<\fRAnchors the single character regular expression or subexpressionimmediately following it to the beginning of a word.(This may not be available) .TP 8\fR\e>\fRAnchors the single character regular expression or subexpressionimmediately following it to the end of a word.(This may not be available) .TP 8\fR\e(\fIre\fR\e)\fRDefines a subexpression.IR re .Subexpressions may be nested.A subsequent backreference of the form \fI`\en'\fR, where.I nis a number in the range [1,9], expands to the text matched by the.IR n thsubexpression.For example, the regular expression `\e(.*\e)\e1' matches any stringconsisting of identical adjacent substrings.Subexpressions are ordered relative totheir left delimiter. .TP 8*Matches the single character regular expression or subexpressionimmediately preceding it zero or more times. If '*' is the firstcharacter of a regular expression or subexpression, then it matchesitself. The `*' operator sometimes yields unexpected results.For example, the regular expression `b*' matches the beginning ofthe string `abbb' (as opposed to the substring `bbb'), since a null matchis the only left-most match. .TP 8\fR\e{\fIn,m\fR\e}\fR or \fR\e{\fIn,\fR\e}\fR or \fR\e{\fIn\fR\e}\fRMatches the single character regular expression or subexpressionimmediately preceding it at least.I nand at most.I mtimes.If.I mis omitted, then it matches at least.I ntimes.If the comma is also omitted, then it matches exactly.I ntimes. .LPAdditional regular expression operators may be defined depending on theparticular.IR regex (3)implementation. .SS COMMANDSAll.B edcommands are single characters, though some require additonal parameters.If a command's parameters extend over several lines, theneach line except for the lastmust be terminated with a backslash (\\). In general, at most one command is allowed per line.However, most commands accept a print suffix, which is any of.I `p'(print),.I `l'(list) ,or.I `n'(enumerate),to print the last line affected by the command. An interrupt (typically ^C) has the effect of aborting the current commandand returning the editor to command mode. .B edrecognizes the following commands. The commands are shown together withthe default address or address range supplied if none isspecified (in parenthesis). .TP 8(.)aAppends text to the buffer after the addressed line.Text is entered in input mode.The current address is set to last line entered. .TP 8(.,.)cChanges lines in the buffer. The addressed lines are deletedfrom the buffer, and text is appended in their place.Text is entered in input mode.The current address is set to last line entered. .TP 8(.,.)dDeletes the addressed lines from the buffer.If there is a line after the deleted range, then the current address is setto this line. Otherwise the current address is set to the lineLines 1–500 of 1003. Load more
.\" $OpenBSD: t11.1,v 1.2 2007/11/27 16:22:12 martynas Exp $ .\" $NetBSD: ed.1,v 1.13 1995/03/21 09:04:38 cgd Exp $ .\" .TH ED 1 "21 May 1993" .SH NAME .\" ed, red \- text editor ed \- text editor .SH SYNOPSIS ed [-] [-sx] [-p \fIstring\fR] [\fIfile\fR] .\" .LP .\" red [-] [-sx] [-p \fIstring\fR] [\fIfile\fR] .SH DESCRIPTION .B ed is a line-oriented text editor. It is used to create, display, modify and otherwise manipulate text files. .\" .B red .\" is a restricted .\" .BR ed : .\" it can only edit files in the current .\" directory and cannot execute shell commands. If invoked with a .I file argument, then a copy of .I file is read into the editor's buffer. Changes are made to this copy and not directly to .I file itself. Upon quitting .BR ed , any changes not explicitly saved with a .I `w' command are lost. Editing is done in two distinct modes: .I command and .IR input . When first invoked, .B ed is in command mode. In this mode commands are read from the standard input and executed to manipulate the contents of the editor buffer. A typical command might look like: .sp .RS ,s/\fIold\fR/\fInew\fR/g .RE .sp which replaces all occurrences of the string .I old with .IR new . When an input command, such as .I `a' (append), .I `i' (insert) or .I `c' (change), is given, .B ed enters input mode. This is the primary means of adding text to a file. In this mode, no commands are available; instead, the standard input is written directly to the editor buffer. Lines consist of text up to and including a .IR newline character. Input mode is terminated by entering a single period (\fI.\fR) on a line. All .B ed commands operate on whole lines or ranges of lines; e.g., the .I `d' command deletes lines; the .I `m' command moves lines, and so on. It is possible to modify only a portion of a line by means of replacement, as in the example above. However even here, the .I `s' command is applied to whole lines at a time. In general, .B ed commands consist of zero or more line addresses, followed by a single character command and possibly additional parameters; i.e., commands have the structure: .sp .RS .I [address [,address]]command[parameters] .RE .sp The address(es) indicate the line or range of lines to be affected by the command. If fewer addresses are given than the command accepts, then default addresses are supplied. .SS OPTIONS .TP 8 -s Suppresses diagnostics. This should be used if .BR ed 's standard input is from a script. .TP 8 -x Prompts for an encryption key to be used in subsequent reads and writes (see the .I `x' command). .TP 8 .RI \-p \ string Specifies a command prompt. This may be toggled on and off with the .I `P' command. .TP 8 .I file Specifies the name of a file to read. If .I file is prefixed with a bang (!), then it is interpreted as a shell command. In this case, what is read is the standard output of .I file executed via .IR sh (1). To read a file whose name begins with a bang, prefix the name with a backslash (\\). The default filename is set to .I file only if it is not prefixed with a bang. .SS LINE ADDRESSING An address represents the number of a line in the buffer. .B ed maintains a .I current address which is typically supplied to commands as the default address when none is specified. When a file is first read, the current address is set to the last line of the file. In general, the current address is set to the last line affected by a command. A line address is constructed from one of the bases in the list below, optionally followed by a numeric offset. The offset may include any combination of digits, operators (i.e., .IR + , .I - and .IR ^ ) and whitespace. Addresses are read from left to right, and their values are computed relative to the current address. One exception to the rule that addresses represent line numbers is the address .I 0 (zero). This means "before the first line," and is legal wherever it makes sense. An address range is two addresses separated either by a comma or semi-colon. The value of the first address in a range cannot exceed the value of the second. If only one address is given in a range, then the second address is set to the given address. If an .IR n- tuple of addresses is given where .I n > 2, then the corresponding range is determined by the last two addresses in the .IR n- tuple. If only one address is expected, then the last address is used. Each address in a comma-delimited range is interpreted relative to the current address. In a semi-colon-delimited range, the first address is used to set the current address, and the second address is interpreted relative to the first. The following address symbols are recognized. .TP 8 \&. The current line (address) in the buffer. .TP 8 $ The last line in the buffer. .TP 8 n The .IR n th, line in the buffer where .I n is a number in the range .I [0,$]. .TP 8 - or ^ The previous line. This is equivalent to .I -1 and may be repeated with cumulative effect. .TP 8 -\fIn\fR or ^\fIn\fR The .IR n th previous line, where .I n is a non-negative number. .TP 8 + The next line. This is equivalent to .I +1 and may be repeated with cumulative effect. .TP 8 +\fIn\fR or whitespace\fIn\fR The .IR n th next line, where .I n is a non-negative number. .I whitespace followed by a number .I n is interpreted as .IR +n . .TP 8 , \fRor\fB % The first through last lines in the buffer. This is equivalent to the address range .I 1,$. .TP 8 ; The current through last lines in the buffer. This is equivalent to the address range .I .,$. .TP 8 .RI / re/ The next line containing the regular expression .IR re . The search wraps to the beginning of the buffer and continues down to the current line, if necessary. // repeats the last search. .TP 8 .RI ? re? The previous line containing the regular expression .IR re . The search wraps to the end of the buffer and continues up to the current line, if necessary. ?? repeats the last search. .TP 8 .RI \' lc The line previously marked by a .I `k' (mark) command, where .I lc is a lower case letter. .SS REGULAR EXPRESSIONS Regular expressions are patterns used in selecting text. For example, the .B ed command .sp .RS g/\fIstring\fR/ .RE .sp prints all lines containing .IR string . Regular expressions are also used by the .I `s' command for selecting old text to be replaced with new. In addition to a specifying string literals, regular expressions can represent classes of strings. Strings thus represented are said to be matched by the corresponding regular expression. If it is possible for a regular expression to match several strings in a line, then the left-most longest match is the one selected. The following symbols are used in constructing regular expressions: .TP 8 c Any character .I c not listed below, including `{', '}', `(', `)', `<' and `>', matches itself. .TP 8 \fR\e\fIc\fR Any backslash-escaped character .IR c , except for `{', '}', `(', `)', `<' and `>', matches itself. .TP 8 \fR.\fR Matches any single character. .TP 8 .I [char-class] Matches any single character in .IR char-class . To include a `]' in .IR char-class , it must be the first character. A range of characters may be specified by separating the end characters of the range with a `-', e.g., `a-z' specifies the lower case characters. The following literal expressions can also be used in .I char-class to specify sets of characters: .sp \ \ [:alnum:]\ \ [:cntrl:]\ \ [:lower:]\ \ [:space:] .PD 0 \ \ [:alpha:]\ \ [:digit:]\ \ [:print:]\ \ [:upper:] .PD 0 \ \ [:blank:]\ \ [:graph:]\ \ [:punct:]\ \ [:xdigit:] .sp If `-' appears as the first or last character of .IR char-class , then it matches itself. All other characters in .I char-class match themselves. .sp Patterns in .I char-class of the form: .sp \ \ [.\fIcol-elm\fR.] or, .PD 0 \ \ [=\fIcol-elm\fR=] .sp where .I col-elm is a .I collating element are interpreted according to .IR locale (5) (not currently supported). See .IR regex (3) for an explanation of these constructs. .TP 8 [^\fIchar-class\fR] Matches any single character, other than newline, not in .IR char-class . .IR char-class is defined as above. .TP 8 ^ If `^' is the first character of a regular expression, then it anchors the regular expression to the beginning of a line. Otherwise, it matches itself. .TP 8 $ If `$' is the last character of a regular expression, it anchors the regular expression to the end of a line. Otherwise, it matches itself. .TP 8 \fR\e<\fR Anchors the single character regular expression or subexpression immediately following it to the beginning of a word. (This may not be available) .TP 8 \fR\e>\fR Anchors the single character regular expression or subexpression immediately following it to the end of a word. (This may not be available) .TP 8 \fR\e(\fIre\fR\e)\fR Defines a subexpression .IR re . Subexpressions may be nested. A subsequent backreference of the form \fI`\en'\fR, where .I n is a number in the range [1,9], expands to the text matched by the .IR n th subexpression. For example, the regular expression `\e(.*\e)\e1' matches any string consisting of identical adjacent substrings. Subexpressions are ordered relative to their left delimiter. .TP 8 * Matches the single character regular expression or subexpression immediately preceding it zero or more times. If '*' is the first character of a regular expression or subexpression, then it matches itself. The `*' operator sometimes yields unexpected results. For example, the regular expression `b*' matches the beginning of the string `abbb' (as opposed to the substring `bbb'), since a null match is the only left-most match. .TP 8 \fR\e{\fIn,m\fR\e}\fR or \fR\e{\fIn,\fR\e}\fR or \fR\e{\fIn\fR\e}\fR Matches the single character regular expression or subexpression immediately preceding it at least .I n and at most .I m times. If .I m is omitted, then it matches at least .I n times. If the comma is also omitted, then it matches exactly .I n times. .LP Additional regular expression operators may be defined depending on the particular .IR regex (3) implementation. .SS COMMANDS All .B ed commands are single characters, though some require additonal parameters. If a command's parameters extend over several lines, then each line except for the last must be terminated with a backslash (\\). In general, at most one command is allowed per line. However, most commands accept a print suffix, which is any of .I `p' (print), .I `l' (list) , or .I `n' (enumerate), to print the last line affected by the command. An interrupt (typically ^C) has the effect of aborting the current command and returning the editor to command mode. .B ed recognizes the following commands. The commands are shown together with the default address or address range supplied if none is specified (in parenthesis). .TP 8 (.)a Appends text to the buffer after the addressed line. Text is entered in input mode. The current address is set to last line entered. .TP 8 (.,.)c Changes lines in the buffer. The addressed lines are deleted from the buffer, and text is appended in their place. Text is entered in input mode. The current address is set to last line entered. .TP 8 (.,.)d Deletes the addressed lines from the buffer. If there is a line after the deleted range, then the current address is set to this line. Otherwise the current address is set to the line