⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sed.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
and can be followed with white space.The<i>commands</i>can be preceded by white space.The terminating"}"must be preceded by anewline characterand then zero or moreblank characters.<p><dl compact><dt><b>[</b><i>2addr</i><b>] {</b><i>command-list</i><dd><dt><b>}</b><dd>Execute<i>command-list</i>only when the pattern space is selected.<dt><b>[</b><i>1addr</i><b>]a\</b><dd><dt><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text</i><dd>Write<i>text</i>to standard outputjust before each attempt to fetch a line of input, whether byexecuting the<b>N</b>command or by beginning a new cycle.<dt><b>[</b><i>2addr</i><b>]b&nbsp;[</b><i>label</i><b>]</b><dd>Branch to the<b>:</b>command bearing the<i>label</i>.If<i>label</i>is not specified, branch to the end of the script.The implementation supports<i>labels</i>recognised as unique up to at least 8 characters;the actual length (greater than or equal to 8) that is supportedby the implementation is unspecified.It is unspecified whether exceeding a label lengthcauses an error or a silent truncation.<dt><b>[</b><i>2addr</i><b>]c\</b><dd><dt><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text</i><dd>Delete the pattern space.With a 0 or 1 address or at the end of a 2-address range, place<i>text</i>on the output.<dt><b>[</b><i>2addr</i><b>]d</b><dd>Delete the pattern space and start the next cycle.<dt><b>[</b><i>2addr</i><b>]D</b><dd>Delete the initial segment of the pattern space up to and includingthe firstnewline characterand start the next cycle.<dt><b>[</b><i>2addr</i><b>]g</b><dd>Replace the contents of the pattern spaceby the contents of the hold space.<dt><b>[</b><i>2addr</i><b>]G</b><dd>Append to the pattern space anewline characterfollowed by the contents of the hold space.<dt><b>[</b><i>2addr</i><b>]h</b><dd>Replace the contents of the hold spacewith the contents of the pattern space.<dt><b>[</b><i>2addr</i><b>]H</b><dd>Append to the hold space anewline characterfollowed by the contents of the pattern space.<dt><b>[</b><i>1addr</i><b>]i\</b><dd><dt><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text</i><dd>Write<i>text</i>to standard output.<dt><b>[</b><i>2addr</i><b>]l</b><dd>(The letter ell.)Write the pattern space to standard output 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>&nbsp;</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 that tablewill be written as one three-digit octal number(with a precedingbackslash 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.Long lines will be folded, with the point offolding indicated by writing abackslash followed by anewline 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 "$".<dt><b>[</b><i>2addr</i><b>]n</b><dd>Write the pattern space to standard outputif the default output has not been suppressed, andreplace the pattern space with the next line of input.<dt><b>[</b><i>2addr</i><b>]N</b><dd>Append the next line of input to the pattern space, usingan embeddednewline characterto separate the appended material from the original material.Note that the current line number changes.<dt><b>[</b><i>2addr</i><b>]p</b><dd>Write the pattern space to standard output.<dt><b>[</b><i>2addr</i><b>]P</b><dd>Write the pattern space, up to the firstnewline character,to standard output.<dt><b>[</b><i>1addr</i><b>]q</b><dd>Branch to the end of the script and quit without starting a new cycle.<dt><b>[</b><i>1addr</i><b>]</b>r <i>rfile</i><dd>Copy the contents of<i>rfile</i>to standard outputjust before each attempt to fetch a line of input.If<i>rfile</i>does not exist or cannot be read,it is treated as if it were an empty file,causing no error condition.<dt><b>[</b><i>2addr</i><b>]s/</b><i>regular expression</i><b>/</b><i>replacement</i><b>/</b><i>flags</i><dd>Substitute the<i>replacement</i>string for instances of the<i>regular expression</i>in the pattern space.Any character other thanbackslashornewlinecan be used instead of a slash todelimit the RE and the replacement.Within the RE and the replacement,the RE delimiter itself can be used as a literalcharacter if it is preceded by a backslash.An ampersand (<b>&amp;</b>) appearing in the<i>replacement</i>will be replaced by the string matching the RE.The special meaning of "&amp;" in this context can besuppressed by preceding it by backslash.The characters<b>\</b><i>n</i>,where<i>n</i>is a digit,will be replaced by the text matched by thecorresponding backreference expression.For each backslash (\) encountered in scanning<i>replacement</i>from beginning to end, the following character loses its special meaning(if any).It is unspecified what special meaning is given to any characterother than &amp;, \ or digits.A line can be split by substituting anewlinecharacter into it.The application must escape thenewline characterin the<i>replacement</i>by preceding it by backslash.A substitution is considered to have beenperformed even if the replacement string is identical to thestring that it replaces.The value of<i>flags</i>must be zero or more of:<dl compact><dt><i>n</i><dd>Substitute for the <i>n</i>th occurrence only of the<i>regular expression</i>found within the pattern space.<dt><b>g</b><dd>Globally substitute for all non-overlapping instances of the<i>regular expression</i>rather than just thefirst one.If bothgand<i>n</i>are specified,the results are unspecified.<dt><b>p</b><dd>Write the pattern space to standard output if a replacement was made.<dt><b>w</b> <i>wfile</i><dd>Write.Append the pattern space to<i>wfile</i>if a replacement was made.</dl><br><p><dt><b>[</b><i>2addr</i><b>]t&nbsp;[</b><i>label</i><b>]</b><dd>Test.Branch to the<b>:</b>command bearing the<i>label</i>if anysubstitutions have been made since the most recentreading of an input line or execution of a<b>t</b>.If<i>label</i>is not specified, branch to the end of the script.<p><dt><b>[</b><i>2addr</i><b>]w</b> <i>wfile</i><dd>Append (write) the pattern space to<i>wfile</i>.<p><dt><b>[</b><i>2addr</i><b>]x</b><dd>Exchange the contents of the pattern and hold spaces.<p><dt><b>[</b><i>2addr</i><b>]y/</b><i>string1</i><b>/</b><i>string2</i><b>/</b><dd>Replace all occurrences of characters in<i>string1</i>with the corresponding characters in<i>string2</i>.If the number of characters in<i>string1</i>and<i>string2</i>are not equal, or if any of the characters in<i>string1</i>appear more than once, the results are undefined.Any character other than backslash or newlinecan be used instead of slash to delimit the strings.Within<i>string1</i>and<i>string2</i>,the delimiter itself can be used as a literalcharacter if it is preceded by a backslash.<p><dt><b>[</b><i>2addr</i><b>]!</b><i>command</i><dd><p><dt><b>[</b><i>2addr</i><b>]!{</b><i>command-list</i><dd><p><dt><b>}</b><dd>Apply the<i>command</i>or<i>command-list</i>only to the lines that are notselected by the addresses.<p><dt><b>[</b><i>0addr</i><b>]:</b><i>label</i><dd>This command does nothing; it bears a<i>label</i>for the<b>b</b>and<b>t</b>commands to branch to.<p><dt><b>[</b><i>1addr</i><b>]=</b><dd>Write the following to standard output:<p><code><tt>"%d\n"</tt>, &lt;<i>current line number</i>&gt;</code><p><dt><b>[</b><i>0addr</i><b>]</b><dd>An empty command is ignored.<p><dt><b>[</b><i>0addr</i><b>]#</b><dd>The"#"and the remainder of the line are ignored(treated as a comment), with the single exception thatif the first two characters in the file are#n,the default output is suppressed;this is the equivalent of specifying<b>-n</b>on the command line.<p></dl></blockquote><h4><a name = "tag_001_014_1986">&nbsp;</a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>Successful completion.<dt>&gt;0<dd>An error occurred.</dl></blockquote><h4><a name = "tag_001_014_1987">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_1988">&nbsp;</a>APPLICATION USAGE</h4><blockquote>Regular expressions match entire strings,not just individual lines,but anewline characteris matched by\nin a<i>sed</i>RE; a newline character is not allowed in an RE.Also note that\ncannot be used to match anewline characterat the end of an arbitrary input line;newline charactersappear in the pattern space as a result of the<b>N</b>editing command.<br></blockquote><h4><a name = "tag_001_014_1989">&nbsp;</a>EXAMPLES</h4><blockquote>This<i>sed</i>script simulates the BSD<i><a href="cat.html">cat</a></i><b>-s</b>command, squeezing excess blank lines from standard input.<pre><code>sed -n '# Write non-empty lines././ {    p    d    }# Write a single empty line, then look for more empty lines./^$/    p# Get next line, discard the held &lt;newline&gt; (empty line),# and look for more empty lines.:Empty/^$/    {    N    s/.//    b Empty    }# Write the non-empty line before going back to search# for the first in a set of empty lines.    p'</code></pre></blockquote><h4><a name = "tag_001_014_1990">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns aboutparts of this interface definition to the IEEE PASC Shell and Utilities Working Groupwhich is identifying the corrections.A future revision of this specification will align withIEEE Std. 1003.2b when finalised.</blockquote><h4><a name = "tag_001_014_1991">&nbsp;</a>SEE ALSO</h4><blockquote><i><a href="awk.html">awk</a></i>,<i><a href="ed.html">ed</a></i>,<i><a href="grep.html">grep</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX &reg; is a registered Trademark of The Open Group.<br>Copyright &copy; 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -