📄 ed.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>ed</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_529"> </a>NAME</h4><blockquote>ed - edit text</blockquote><h4><a name = "tag_001_014_530"> </a>SYNOPSIS</h4><blockquote><pre><code>ed <b>[</b>-p <i>string</i><b>][</b>-s<b>][</b><i>file</i><b>]</b>ed <b>[</b>-p <i>string</i><b>][</b>-<b>][</b><i>file</i><b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_531"> </a>DESCRIPTION</h4><blockquote><br>The<i>ed</i>utility is a line-oriented text editor that uses two modes:<i>command mode</i>and<i>input mode</i>.In command mode the input characters are interpreted as commands,and in input mode they are interpreted as text.See the EXTENDED DESCRIPTION section.</blockquote><h4><a name = "tag_001_014_532"> </a>OPTIONS</h4><blockquote>The<i>ed</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> , except for its non-standard usage of "-".<p>The following options are supported:<dl compact><dt><b>-p </b><i>string</i><dd>Use<i>string</i>as the prompt string when in command mode.By default, there is no prompt string.<dt><b>-s</b><dd>Suppress the writing of byte counts by<b>e</b>,<b>E</b>,<b>r</b>and<b>w</b>commands and of the "!" prompt after a<b>!</b><i>command</i>.<dt><b>-</b><dd>Same as the <b>-s</b> option.</dl></blockquote><h4><a name = "tag_001_014_533"> </a>OPERANDS</h4><blockquote>The following operand is supported:<dl compact><dt><i>file</i><dd>If the<i>file</i>argument is given,<i>ed</i>will simulate an<b>e</b>commandon the file named by the pathname,<i>file</i>,before accepting commands from the standard input.</dl></blockquote><h4><a name = "tag_001_014_534"> </a>STDIN</h4><blockquote>The standard input must be a text file consisting of commands,as described in the EXTENDED DESCRIPTION section.</blockquote><h4><a name = "tag_001_014_535"> </a>INPUT FILES</h4><blockquote>The input files must be text files.</blockquote><h4><a name = "tag_001_014_536"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>ed</i>:<dl compact><dt><i>HOME</i><dd>Determine the pathname of the user's home directory.<dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_COLLATE</i><dd>Determine the locale for thebehaviour of ranges, equivalence classesand multi-character collating elementswithin regular expressions.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments and input files) andthe behaviour of character classes within regular expressions.<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard errorand informative messages written to standard output.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i></dl></blockquote><h4><a name = "tag_001_014_537"> </a>ASYNCHRONOUS EVENTS</h4><blockquote>The<i>ed</i>utility will take thestandard action for all signals (see the ASYNCHRONOUS EVENTS sectionin<a href="utildes.html">Utility Description Defaults</a><xref href=utildes></xref>)with the following exceptions:<dl compact><dt>SIGINT<dd>The<i>ed</i>utility will interrupt its current activity, write the string?\nto standard output, and return tocommand mode (see the EXTENDED DESCRIPTION section).<dt>SIGHUP<dd>If the buffer is not empty and has changed since the last write,the<i>ed</i>utility will attempt to write a copy of the buffer in afile.First, the file named<b>ed.hup</b>in the current directory will beused; if that fails, the file named<b>ed.hup</b>in the directorynamed by the<i>HOME</i>environment variable will be used.In any case, the<i>ed</i>utility will exit without returning to command mode.</dl></blockquote><h4><a name = "tag_001_014_538"> </a>STDOUT</h4><blockquote>Various editing commands and the prompting feature (see<b>-p</b>)write to standard output,as described in the EXTENDED DESCRIPTION section.</blockquote><h4><a name = "tag_001_014_539"> </a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_001_014_540"> </a>OUTPUT FILES</h4><blockquote>The output files are text files whose formats aredependent on the editing commands given.</blockquote><h4><a name = "tag_001_014_541"> </a>EXTENDED DESCRIPTION</h4><blockquote>The<i>ed</i>utility operates on a copy of the file it is editing; changes madeto the copy will have no effect on the file until a<b>w</b>(write)command is given.The copy of the text is called the<i>buffer</i>.<p>Commands to<i>ed</i>have a simple and regular structure: zero, one or two<i>addresses</i>followed by a single-character<i>command</i>,possibly followed by parameters to that command.These addresses specify one or more lines in the buffer.Every command that requires addresses has default addresses,so that the addresses very often can be omitted.If the<b>-p</b>option is specified, the prompt string will be written to standardoutput before each command is read.<p>In general, only one command can appear on a line.Certain commands allow text to be input.This text is placed in the appropriate place in the buffer.While<i>ed</i>is accepting text, it is saidto be in <i>input mode</i>.In this mode, no commands are recognised;all input is merely collected.Input mode isterminated by entering a line consisting of two characters:a period(.)followed by anewline character.This line is not considered part of the input text.<h5><a name = "tag_001_014_541_001"> </a>Regular Expressions in ed</h5>The<i>ed</i>utility supportsbasic regular expressions, as described inthe <b>XBD</b> specification, <a href="../xbd/re.html#tag_007_003"><b>Basic Regular Expressions</b> </a> .Since regular expressions in<i>ed</i>are alwaysmatched against single lines, never against any larger section oftext, there is no way for a regular expression to match anewline character.A null RE is equivalent to the last RE encountered.<p>Regular expressions are used in addresses to specify lines, and in somecommands (for example, the<b>s</b>substitute command) to specify portions of a line to besubstituted.<h5><a name = "tag_001_014_541_002"> </a>Addresses in ed</h5>Addressing in<i>ed</i>relates to the <i>current line</i>.Generally, the current line is the last line affected by a command.The <i>current line number</i> is the address (line number) ofthe current line.The exact effect on the current line numberis discussed under the description of each command.Thef,h,H,k,P,w,"=" and "!" commands do not modify the current line number.<p>Addresses are constructed as follows:<ol><p><li>The character "." (period) addresses the current line.<p><li>The character "$" addresses the last line of the buffer.<p><li>A positive decimal number<i>n</i>addresses the<i>n</i>thline of the buffer.The first line in the buffer is line number 1.<p><li><b>'</b><i>x</i> addresses the line marked with themark name character <i>x,</i>which must be a lower-case letter from the portable character set.Lines can be marked with thekcommand.<p><li>An RE enclosed by slashes(/)addresses the first line found by searchingforward from the line following the current line toward the end of thebuffer and stopping at the first line containing a string matching the RE.An address consisting of a null RE delimited by slashes(//)addresses the next line containing the last RE encountered.If necessary, the search will wrap around to the beginning of the bufferand continue up to and including the current line, so that the entirebuffer is searched.Within the RE, the sequence\/represents a literalslash instead of the RE delimiter.<p><li>An RE enclosed in question-marks(?)addresses the first line found by searchingbackward from the line preceding the current line toward the beginning ofthe buffer and stopping at the first line containing a string matching the RE.If necessary, the search wraps around to the end of the bufferand continues up to and including the current line.Within the RE, the sequence\?represents a literal question-mark instead of the RE delimiter.<p><li>An address followed by a plus sign(+)or a minus sign(-)followed bya decimal number specifies that address plus(respectively minus) the indicated number of lines.The plus sign can be omitted.<p><li>If an address begins with "+" or "-", the addition or subtractionis taken with respect to the current line number; for example,-5is understood to mean.-5.<p><li>If an address ends with "+" or "-",then 1 will be added to or subtracted from the address, respectively.As a consequence of this rule and of rule 8 immediately above,the address "-" refers to the line preceding the current line.Moreover, trailing "+" and "-" characters have a cumulative effect, so--refers to the current line number less 2.<p><li>A comma(,)stands for the address pair1,$,while a semicolon(;)stands for the pair.,$.<p></ol><p>Commands require zero, one or two addresses.Commands that require no addresses regard the presenceof an address as an error.Commands that accept one or two addressesassume default addresses when no addresses are given.If one address is given to a command that allows two addresses,the command will operate as if it were specified as:<p><code><i>given_address</i>;.<i>command</i></code><p>If more addresses are given than such a command requires,the results are undefined.<p>Typically, addresses are separated from each other by a comma.They can also be separated by a semicolon.In the latter case, the current line number(.)is set to the first address,and only then will the second address be calculated.This feature can be used to determine the startingline for forward and backward searches (see rules 5 and 6 above).The second address of any two-address sequencecorresponds to a line thatdoes not precede,in the buffer, the line corresponding to the first address.<h5><a name = "tag_001_014_541_003"> </a>Commands in ed</h5>In the following list of<i>ed</i>commands, the default addressesare shown in parentheses.The number of addresses shown in the default are thenumber expected by the command.The parentheses are not part ofthe address; they show that the given addresses arethe default.<p>It is generally invalid for more than onecommand to appear on a line.However, any command(except<b>e</b>,<b>E</b>,<b>f</b>,<b>q</b>,<b>Q</b>,<b>r</b>,<b>w</b>and<b>!</b>)can be suffixed by the letter<b>l</b>,<b>n</b>or<b>p</b>;in which case, except for the<b>l</b>,<b>n</b>and<b>p</b>commands,the command will be executed and thenthe new current line will be writtenas described below under the<b>l</b>,<b>n</b>and<b>p</b>commands.When an<b>l</b>,<b>n</b>or<b>p</b>suffix is used with an<b>l</b>,<b>n</b>or<b>p</b>command, the command will write tostandard output as described below,but it is unspecified whether thesuffix writes the current line againin the requested format or whetherthe suffix has no effect.For example, the<b>pl</b>command (base<b>p</b>command with an<b>l</b>suffix) will either write just thecurrent line or will write it twice once as specified for<b>p</b>and once as specified for<b>l</b>.Also, the<b>g</b>,<b>G</b>,<b>v</b>and<b>V</b>commands takes a command as a parameter.<p>Each address component can be preceded by zero or moreblank characters.The command letter can be preceded by zero or moreblank characters.If a suffix letter(<b>l</b>,<b>n</b>or<b>p</b>)is given, it must immediately follow the command.<p>The<b>e</b>,<b>E</b>,<b>f</b>,<b>r</b>and<b>w</b>commands take an optional<i>file</i>parameter, separated from the command letter by one or moreblank characters.<p>If changes have been made in the buffer since the last<b>w</b>command that wrote the entire buffer,<i>ed</i>will warn the user if an attempt is made to destroythe editor buffer via the<b>e</b>or<b>q</b>commands.The<i>ed</i>utility 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.If the<b>e</b>or<b>q</b>commandis repeated with no intervening command, it will take effect.<p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -