📄 ed.html
字号:
If an end-of-file is detected on standard input when a commandis expected, the<i>ed</i>utility acts as if a<b>q</b>command had been entered.<p>If the closing delimiter of an RE or of areplacement string (for example,<b>/</b>)in a<b>g</b>,<b>G</b>,<b>s</b>,<b>v</b>or<b>V</b>command would be the last character before a newline character,that delimiter can be omitted, inwhich case the addressed line is written.For example,the following pairs of commands are equivalent:<p><code><dl compact><dt>s/s1/s2<dd>s/s1/s2/p<dt>g/s1<dd>g/s1/p<dt>?s1<dd>?s1?</dl></code><p>If an invalid command is entered,<i>ed</i>will write the string:<pre><code>"?\n"</code></pre>(followed by an explanatory message if<i>help mode</i>has been enabled via the<b>H</b>command) to standard output andwill continue in command mode with the current line number unchanged.<h5><a name = "tag_001_014_541_004"> </a>Append Command</h5><pre><code><i>Synopsis</i>: (.)a <<i>text</i>> .</code></pre><p>The<b>a</b>command reads the given textand appends it after the addressed line;the current line number will becomethe address of the last inserted line or, if therewere none, the addressed line.Address 0 is valid for this command;it causes the appended text to be placedat the beginning of the buffer.<h5><a name = "tag_001_014_541_005"> </a>Change Command</h5><pre><code><i>Synopsis</i>: (.,.)c <<i>text</i>> .</code></pre><p>The<b>c</b>command deletes the addressed lines, then accepts inputtext that replaces these lines;the current line will beset to the address of the last line input; or, if there were none,at the line after the last line deleted;if the lines deleted were originally at the end of the buffer,the current linenumber will be set to the address of the new last line; if no lines remainin the buffer, the current line number will be set to zero.<h5><a name = "tag_001_014_541_006"> </a>Delete Command</h5><pre><code><i>Synopsis</i>: (.,.)d</code></pre><p>The<b>d</b>command deletes the addressed lines from the buffer.The address of the line after the last line deleted will becomethe current line number;if the lines deleted were originally at the end of the buffer,the current linenumber will be set to the address of the new last line; if no lines remainin the buffer, the current line number will be set to zero.<h5><a name = "tag_001_014_541_007"> </a>Edit Command</h5><pre><code><i>Synopsis</i>: e <b>[</b><i>file</i><b>]</b></code></pre><p>The<b>e</b>command deletes the entire contents of the bufferand then reads in the file named by the pathname<i>file</i>.The current linenumber will be set to the address of the last line of the buffer.If no pathname is given, the currently remembered pathname,if any, will be used(see the<b>f</b>command).The number of bytes read will be written to standard output, unless the<b>-s</b>option was specified,in the following format:<p><code><tt>"%d\n"</tt>, <<i>number of bytes read</i>></code><p>The name <i>file</i>will be remembered for possible use as a default pathnamein subsequent<b>e</b>,<b>E</b>,<b>r</b>and<b>w</b>commands.If<i>file</i>is replaced by<b>!</b>,the rest of the linewill be taken to be ashell command line whose output is to be read.Such a shell command line is not remembered as the current<i>file</i>.All marks will be discarded upon the completion of a successful<b>e</b>command.If the buffer has changed since the last time the entire bufferwas written, the user will be warned, as described previously.<h5><a name = "tag_001_014_541_008"> </a>Edit Without Checking Command</h5><pre><code><i>Synopsis</i>: E <b>[</b><i>file</i><b>]</b></code></pre><p>The<b>E</b>command possesses all properties and restrictions of the<b>e</b>command except that the editor will not check to seeif any changes have been made to the buffer since the lastwcommand.<h5><a name = "tag_001_014_541_009"> </a>Filename Command</h5><pre><code><i>Synopsis</i>: f <b>[</b><i>file</i><b>]</b></code></pre><p>If<i>file</i>is given, the<b>f</b>command will change the currently remembered pathname to<i>file</i>;whether the name is changed or not,it then will write the (possibly new) currently remembered pathnameto the standard outputin the following format:<p><code><tt>"%s\n"</tt>, <<i>pathname</i>></code><p>The current line number is unchanged.<h5><a name = "tag_001_014_541_010"> </a>Global Command</h5><pre><code><i>Synopsis</i>: (1,$)g/<i>RE</i>/<i>command list</i></code></pre><p>In the<b>g</b>command, the first step is to mark every line that matchesthe given<i>RE.</i>Then, for every such line, the given<i>command list</i> will be executed withthe current line number set to the address of that line.When the<b>g</b>command completes, the current line number will havethe value assigned by the last command in the command list.If there were no matching lines, the current line number will not be changed.A single command or the first of a list of commandswill appear on the same line as the global command.All lines of a multi-line list except the last line will be ended with abackslash; the<b>a</b>,<b>i</b>and<b>c</b>commands and associated input are permitted.The.terminating input mode can be omitted if it would be thelast line of the <i>command list</i>.An empty <i>command list</i> is equivalent to the<b>p</b>command.The use of the<b>g</b>,<b>G</b>,<b>v</b>,<b>V</b>and<b>!</b>commands in the<i>command list</i>produces undefined results.Any character other thanspace or newline can be used instead of a slash to delimit the<i>RE</i>.Within the<i>RE</i>,the<i>RE</i>delimiter itself can be used as a literalcharacter if it is preceded by a backslash.<h5><a name = "tag_001_014_541_011"> </a>Interactive Global Command</h5><pre><code><i>Synopsis</i>: (1,$)G/<i>RE</i>/</code></pre><p>In the<b>G</b>command, the first stepis to mark every line that matches the given<i>RE.</i>Then, for every such line, that line will be written,the current line number will be set to the address of that line, and any onecommand (other than one of the<b>a</b>,<b>c</b>,<b>i</b>,<b>g</b>,<b>G</b>,<b>v</b>and<b>V</b>commands)can be input and will be executed.Anewline characteracts as a null command(causing no action to be taken on the current line);an<b>&</b>causes the reexecutionof the most recent non-null command executed withinthe current invocation of<b>G</b>.Note that the commands input as part of the execution of the<b>G</b>command can address and affect any lines in the buffer.The final value of the current line number will be the value set bythe last command successfully executed.(Note that the lastcommand successfully executed will be the<b>G</b>command itself if acommand fails or the null command is specified.)If there wereno matching lines, the current line number will not be changed.The <b>G</b>command can be terminated by a SIGINT signal.Any character other than space or newlinecan be used instead of a slash to delimit the<i>RE</i>and the replacement.Within the<i>RE</i>,the<i>RE</i>delimiter itself can be used as a literalcharacter if it is preceded by a backslash.<h5><a name = "tag_001_014_541_012"> </a>Help Command</h5><pre><code><i>Synopsis</i>: h</code></pre><p>The<b>h</b>command writes a shortmessage to standard output that explainsthe reason for the most recent<b>?</b>notification.The current line number is unchanged.<h5><a name = "tag_001_014_541_013"> </a>Help-mode Command</h5><pre><code><i>Synopsis</i>: H</code></pre><p>The<b>H</b>command causes<i>ed</i>to enter a mode in whichhelp messages (see the<b>h</b>command) will be written to standard output for all subsequent<b>?</b>notifications.The<b>H</b>command alternatively will turn this modeon and off; it is initially off.If the help-mode is being turned on, the<b>H</b>command also will explain the previous<b>?</b>notification, if there was one.The current line number is unchanged.<h5><a name = "tag_001_014_541_014"> </a>Insert Command</h5><pre><code><i>Synopsis</i>: (.)i <<i>text</i>> .</code></pre><p>The<b>i</b>command inserts the given text before the addressed line;.will be left at the last inserted line or, if there was none,at the addressed line.This command differs from the<b>a</b>command only in the placement of the input text.Address 0 is invalid for this command.<h5><a name = "tag_001_014_541_015"> </a>Join Command</h5><pre><code><i>Synopsis</i>: (.,.+1)j</code></pre><p>The<b>j</b>command joins contiguous lines by removing the appropriatenewline characters.If exactly one address is given, this command will do nothing.If lines are joined, the current line number will be set to theaddress of the joined line; otherwise, the current line numberis unchanged.<h5><a name = "tag_001_014_541_016"> </a>Mark Command</h5><pre><code><i>Synopsis</i>: (.)k<i>x</i></code></pre><p>The<b>m</b>command marks the addressed line with name<i>x</i>,which must be a lower-case letterfrom the portable character set.The address'xthen refers to this line;the current line numberis unchanged.<h5><a name = "tag_001_014_541_017"> </a>List Command</h5><pre><code><i>Synopsis</i>: (.,.)l</code></pre><p>The<b>l</b>command writes to standard output the addressed lines in avisually unambiguous form.The characters listed in the table inthe <b>XBD</b> specification, <a href="../xbd/notation.html"><b>File Format Notation</b> </a> (\\,\a,\b,\f,\r,\t,\v)will be written as the corresponding escape sequence;the\nin that table is not applicable.Non-printable characters not in the tablewill be written as one three-digit octal number(with a preceding backslash character)for each byte in the character (most significant byte first).If the size of a byte on the system is greater than nine bits,the format used for non-printable characters is implementation-dependent.<p>Long lines will be folded, with the point offolding indicated by writingbackslash/newline character;the length at which folding occurs is unspecified,but should be appropriate for the output device.The end of each line will be marked with a "$".An<b>l</b>command can be appended to any other commandother than<b>e</b>,<b>E</b>,<b>f</b>,<b>q</b>,<b>Q</b>,<b>r</b>,<b>w</b>or<b>!</b>.The current line number will be set to the address of the last line written.<h5><a name = "tag_001_014_541_018"> </a>Move Command</h5><pre><code><i>Synopsis</i>: (.,.)m<i>address</i></code></pre><p>The<b>m</b>command repositions the addressed lines after the lineaddressed by<i>address</i>.Address 0 is valid for<i>address</i>and causes the addressed lines to be moved tothe beginning of the buffer.It is an error if address<i>address</i>falls within the range of moved lines.The current line number will be set to the address of the last line moved.<h5><a name = "tag_001_014_541_019"> </a>Number Command</h5><pre><code><i>Synopsis</i>: (.,.)n</code></pre><p>The<b>n</b>command writes to standard output the addressed lines,preceding each line by its line number and a tab character;the current line number will be set to the address of the last line written.The<b>n</b>command can be appended to any command other than<b>e</b>,<b>E</b>,<b>f</b>,<b>q</b>,<b>Q</b>,<b>r</b>,<b>w</b>or<b>!</b>.<h5><a name = "tag_001_014_541_020"> </a>Print Command</h5><pre><code><i>Synopsis</i>: (.,.)p</code></pre><p>The<b>p</b>command writes to standard output the addressed lines;the current line number will be set to the address of the last line written.The<b>p</b>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -