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

📄 grep.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<p>The remainder of each output line shall depend on the other options specified:</p><ul><li><p>If the <b>-c</b> option is in effect, the remainder of each output line shall contain:</p><pre><tt>"%d\n", &lt;</tt><i>count</i><tt>&gt;</tt></pre></li><li><p>Otherwise, if <b>-c</b> is not in effect and the <b>-n</b> option is in effect, the following shall be written to standardoutput:</p><pre><tt>"%d:", &lt;</tt><i>line number</i><tt>&gt;</tt></pre></li><li><p>Finally, the following shall be written to standard output:</p><pre><tt>"%s", &lt;</tt><i>selected-line contents</i><tt>&gt;</tt></pre></li></ul></blockquote><h4><a name="tag_04_63_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_63_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_63_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_63_14"></a>EXIT STATUS</h4><blockquote><p>The following exit values shall be returned:</p><dl compact><dt>&nbsp;0</dt><dd>One or more lines were selected.</dd><dt>&nbsp;1</dt><dd>No lines were selected.</dd><dt>&gt;1</dt><dd>An error occurred.</dd></dl></blockquote><h4><a name="tag_04_63_15"></a>CONSEQUENCES OF ERRORS</h4><blockquote><p>If the <b>-q</b> option is specified, the exit status shall be zero if an input line is selected, even if an error was detected.Otherwise, default actions shall be performed.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_04_63_16"></a>APPLICATION USAGE</h4><blockquote><p>Care should be taken when using characters in <i>pattern_list</i> that may also be meaningful to the command interpreter. It issafest to enclose the entire <i>pattern_list</i> argument in single quotes:</p><pre><tt>'...'</tt></pre><p>The <b>-e</b> <i>pattern_list</i> option has the same effect as the <i>pattern_list</i> operand, but is useful when<i>pattern_list</i> begins with the hyphen delimiter. It is also useful when it is more convenient to provide multiple patterns asseparate arguments.</p><p>Multiple <b>-e</b> and <b>-f</b> options are accepted and <i>grep</i> uses all of the patterns it is given while matching inputtext lines. (Note that the order of evaluation is not specified. If an implementation finds a null string as a pattern, it isallowed to use that pattern first, matching every line, and effectively ignore any other patterns.)</p><p>The <b>-q</b> option provides a means of easily determining whether or not a pattern (or string) exists in a group of files.When searching several files, it provides a performance improvement (because it can quit as soon as it finds the first match) andrequires less care by the user in choosing the set of files to supply as arguments (because it exits zero if it finds a match evenif <i>grep</i> detected an access or read error on earlier <i>file</i> operands).</p></blockquote><h4><a name="tag_04_63_17"></a>EXAMPLES</h4><blockquote><ol><li><p>To find all uses of the word <tt>"Posix"</tt> (in any case) in file <b>text.mm</b> and write with line numbers:</p><pre><tt>grep -i -n posix text.mm</tt></pre></li><li><p>To find all empty lines in the standard input:</p><pre><tt>grep ^$</tt></pre><p>or:</p><pre><tt>grep -v .</tt></pre></li><li><p>Both of the following commands print all lines containing strings <tt>"abc"</tt> or <tt>"def"</tt> or both:</p><pre><tt>grep -E 'abc|def'<br>grep -F 'abcdef'</tt></pre></li><li><p>Both of the following commands print all lines matching exactly <tt>"abc"</tt> or <tt>"def"</tt> :</p><pre><tt>grep -E '^abc$|^def$'<br>grep -F -x 'abcdef'</tt></pre></li></ol></blockquote><h4><a name="tag_04_63_18"></a>RATIONALE</h4><blockquote><p>This <i>grep</i> has been enhanced in an upwards-compatible way to provide the exact functionality of the historical<i>egrep</i> and <i>fgrep</i> commands as well. It was the clear intention of the standard developers to consolidate the three<i>grep</i>s into a single command.</p><p>The old <i>egrep</i> and <i>fgrep</i> commands are likely to be supported for many years to come as implementation extensions,allowing historical applications to operate unmodified.</p><p>Historical implementations usually silently ignored all but one of multiply-specified <b>-e</b> and <b>-f</b> options, but werenot consistent as to which specification was actually used.</p><p>The <b>-b</b> option was omitted from the OPTIONS section because block numbers are implementation-defined.</p><p>The System V restriction on using <b>-</b> to mean standard input was omitted.</p><p>A definition of action taken when given a null BRE or ERE is specified. This is an error condition in some historicalimplementations.</p><p>The <b>-l</b> option previously indicated that its use was undefined when no files were explicitly named. This behavior washistorical and placed an unnecessary restriction on future implementations. It has been removed.</p><p>The historical BSD <i>grep</i> <b>-s</b> option practice is easily duplicated by redirecting standard output to<b>/dev/null</b>. The <b>-s</b> option required here is from System V.</p><p>The <b>-x</b> option, historically available only with <i>fgrep</i>, is available here for all of the non-obsolescentversions.</p></blockquote><h4><a name="tag_04_63_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_63_20"></a>SEE ALSO</h4><blockquote><p><a href="sed.html"><i>sed</i></a></p></blockquote><h4><a name="tag_04_63_21"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2.</p></blockquote><h4><a name="tag_04_63_22"></a>Issue 6</h4><blockquote><p>The Open Group Corrigendum U029/5 is applied, correcting the SYNOPSIS.</p><p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</p><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XCU/TC1/D6/28 is applied, correcting the examples using the <i>grep</i><b>-F</b> option which did not match the normative description of the <b>-F</b> option.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

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