📄 sed.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>sed</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="sed"></a> <a name="tag_04_126"></a><!-- sed --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_126_01"></a>NAME</h4><blockquote>sed - stream editor</blockquote><h4><a name="tag_04_126_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>sed</tt> <b>[</b><tt>-n</tt><b>]</b> <i>script</i><b>[</b><i>file</i><tt>...</tt><b>]</b><tt><br><br>sed</tt> <b>[</b><tt>-n</tt><b>][</b><tt>-e</tt> <i>script</i><b>]</b><tt>...</tt><b>[</b><tt>-f</tt><i>script_file</i><b>]</b><tt>...</tt><b>[</b><i>file</i><tt>...</tt><b>]</b><tt><br></tt></code></p></blockquote><h4><a name="tag_04_126_03"></a>DESCRIPTION</h4><blockquote><p>The <i>sed</i> utility is a stream editor that shall read one or more text files, make editing changes according to a script ofediting commands, and write the results to standard output. The script shall be obtained from either the <i>script</i> operandstring or a combination of the option-arguments from the <b>-e</b> <i>script</i> and <b>-f</b> <i>script_file</i> options.</p></blockquote><h4><a name="tag_04_126_04"></a>OPTIONS</h4><blockquote><p>The <i>sed</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>, except that the order of presentation of the<b>-e</b> and <b>-f</b> options is significant.</p><p>The following options shall be supported:</p><dl compact><dt><b>-e </b> <i>script</i></dt><dd>Add the editing commands specified by the <i>script</i> option-argument to the end of the script of editing commands. The<i>script</i> option-argument shall have the same properties as the <i>script</i> operand, described in the OPERANDS section.</dd><dt><b>-f </b> <i>script_file</i></dt><dd>Add the editing commands in the file <i>script_file</i> to the end of the script.</dd><dt><b>-n</b></dt><dd>Suppress the default output (in which each line, after it is examined for editing, is written to standard output). Only linesexplicitly selected for output are written.</dd></dl><p>Multiple <b>-e</b> and <b>-f</b> options may be specified. All commands shall be added to the script in the order specified,regardless of their origin.</p></blockquote><h4><a name="tag_04_126_05"></a>OPERANDS</h4><blockquote><p>The following operands shall be supported:</p><dl compact><dt><i>file</i></dt><dd>A pathname of a file whose contents are read and edited. If multiple <i>file</i> operands are specified, the named files shallbe read in the order specified and the concatenation shall be edited. If no <i>file</i> operands are specified, the standard inputshall be used.</dd><dt><i>script</i></dt><dd>A string to be used as the script of editing commands. The application shall not present a <i>script</i> that violates therestrictions of a text file except that the final character need not be a <newline>.</dd></dl></blockquote><h4><a name="tag_04_126_06"></a>STDIN</h4><blockquote><p>The standard input shall be used only if no <i>file</i> operands are specified. See the INPUT FILES section.</p></blockquote><h4><a name="tag_04_126_07"></a>INPUT FILES</h4><blockquote><p>The input files shall be text files. The <i>script_file</i>s named by the <b>-f</b> option shall consist of editingcommands.</p></blockquote><h4><a name="tag_04_126_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>sed</i>:</p><dl compact><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_COLLATE</i></dt><dd><br>Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regularexpressions.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments and input files), and the behavior of character classes within regularexpressions.</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standarderror.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><h4><a name="tag_04_126_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_126_10"></a>STDOUT</h4><blockquote><p>The input files shall be written to standard output, with the editing commands specified in the script applied. If the <b>-n</b>option is specified, only those input lines selected by the script shall be written to standard output.</p></blockquote><h4><a name="tag_04_126_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_126_12"></a>OUTPUT FILES</h4><blockquote><p>The output files shall be text files whose formats are dependent on the editing commands given.</p></blockquote><h4><a name="tag_04_126_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>The <i>script</i> shall consist of editing commands of the following form:</p><pre><b>[</b><i>address</i><b>[</b><tt>,</tt><i>address</i><b>]]</b><i>function</i></pre><p>where <i>function</i> represents a single-character command verb from the list in <a href="#tag_04_126_13_03">Editing Commandsin sed</a> , followed by any applicable arguments.</p><p>The command can be preceded by <blank>s and/or semicolons. The function can be preceded by <blank>s. These optionalcharacters shall have no effect.</p><p>In default operation, <i>sed</i> cyclically shall append a line of input, less its terminating <newline>, into the patternspace. Normally the pattern space will be empty, unless a <b>D</b> command terminated the last cycle. The <i>sed</i> utility shallthen apply in sequence all commands whose addresses select that pattern space, and at the end of the script copy the pattern spaceto standard output (except when <b>-n</b> is specified) and delete the pattern space. Whenever the pattern space is written tostandard output or a named file, <i>sed</i> shall immediately follow it with a <newline>.</p><p>Some of the editing commands use a hold space to save all or part of the pattern space for subsequent retrieval. The pattern andhold spaces shall each be able to hold at least 8192 bytes.</p><h5><a name="tag_04_126_13_01"></a>Addresses in sed</h5><p>An address is either a decimal number that counts input lines cumulatively across files, a <tt>'$'</tt> character that addressesthe last line of input, or a context address (which consists of a BRE, as described in <a href="#tag_04_126_13_02">RegularExpressions in sed</a> , preceded and followed by a delimiter, usually a slash).</p><p>An editing command with no addresses shall select every pattern space.</p><p>An editing command with one address shall select each pattern space that matches the address.</p><p>An editing command with two addresses shall select the inclusive range from the first pattern space that matches the firstaddress through the next pattern space that matches the second. (If the second address is a number less than or equal to the linenumber first selected, only one line shall be selected.) Starting at the first line following the selected range, <i>sed</i> shalllook again for the first address. Thereafter, the process shall be repeated. Omitting either or both of the address components inthe following form produces undefined results:</p><pre><b>[</b><i>address</i><b>[</b><tt>,</tt><i>address</i><b>]]</b></pre><h5><a name="tag_04_126_13_02"></a>Regular Expressions in sed</h5><p>The <i>sed</i> utility shall support the BREs described in the Base Definitions volume of IEEE Std 1003.1-2001, <ahref="../basedefs/xbd_chap09.html#tag_09_03">Section 9.3, Basic Regular Expressions</a>, with the following additions:</p><ul><li><p>In a context address, the construction <tt>"\cBREc"</tt> , where <i>c</i> is any character other than backslash or<newline>, shall be identical to <tt>"/BRE/"</tt> . If the character designated by <i>c</i> appears following a backslash,then it shall be considered to be that literal character, which shall not terminate the BRE. For example, in the context address<tt>"\xabc\xdefx"</tt> , the second <i>x</i> stands for itself, so that the BRE is <tt>"abcxdef"</tt> .</p></li><li><p>The escape sequence <tt>'\n'</tt> shall match a <newline> embedded in the pattern space. A literal <newline> shallnot be used in the BRE of a context address or in the substitute function.</p></li><li><p>If an RE is empty (that is, no pattern is specified) <i>sed</i> shall behave as if the last RE used in the last command applied(either as an address or as part of a substitute command) was specified.</p></li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -