📄 grep.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>grep</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="grep"></a> <a name="tag_04_63"></a><!-- grep --> <!--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_63_01"></a>NAME</h4><blockquote>grep - search a file for a pattern</blockquote><h4><a name="tag_04_63_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>grep</tt> <b>[</b><tt>-E| -F</tt><b>][</b><tt>-c| -l| -q</tt><b>][</b><tt>-insvx</tt><b>]</b> <tt>-e</tt><i>pattern_list...<br></i> <tt> </tt> <i></i><b>[</b><tt>-f</tt><i>pattern_file</i><b>]</b><tt>...</tt><b>[</b><i>file</i><tt>...</tt><b>]</b><tt><br><br>grep</tt> <b>[</b><tt>-E| -F</tt><b>][</b><tt>-c| -l| -q</tt><b>][</b><tt>-insvx</tt><b>][</b><tt>-e</tt><i>pattern_list</i><b>]...<br></b> <tt> </tt> <b></b><tt>-f</tt><i>pattern_file</i><tt>...</tt><b>[</b><i>file</i><tt>...</tt><b>]</b><tt><br><br>grep</tt> <b>[</b><tt>-E| -F</tt><b>][</b><tt>-c| -l| -q</tt><b>][</b><tt>-insvx</tt><b>]</b><i>pattern_list</i><b>[</b><i>file</i><tt>...</tt><b>]</b><tt><br></tt></code></p></blockquote><h4><a name="tag_04_63_03"></a>DESCRIPTION</h4><blockquote><p>The <i>grep</i> utility shall search the input files, selecting lines matching one or more patterns; the types of patterns arecontrolled by the options specified. The patterns are specified by the <b>-e</b> option, <b>-f</b> option, or the<i>pattern_list</i> operand. The <i>pattern_list</i>'s value shall consist of one or more patterns separated by <newline>s;the <i>pattern_file</i>'s contents shall consist of one or more patterns terminated by <newline>. By default, an input lineshall be selected if any pattern, treated as an entire basic regular expression (BRE) as described in the Base Definitions volumeof IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap09.html#tag_09_03">Section 9.3, Basic Regular Expressions</a>,matches any part of the line excluding the terminating <newline>; a null BRE shall match every line. By default, eachselected input line shall be written to the standard output.</p><p>Regular expression matching shall be based on text lines. Since a <newline> separates or terminates patterns (see the<b>-e</b> and <b>-f</b> options below), regular expressions cannot contain a <newline>. Similarly, since patterns are matchedagainst individual lines (excluding the terminating <newline>s) of the input, there is no way for a pattern to match a<newline> found in the input.</p></blockquote><h4><a name="tag_04_63_04"></a>OPTIONS</h4><blockquote><p>The <i>grep</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>.</p><p>The following options shall be supported:</p><dl compact><dt><b>-E</b></dt><dd>Match using extended regular expressions. Treat each pattern specified as an ERE, as described in the Base Definitions volumeof IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap09.html#tag_09_04">Section 9.4, Extended Regular Expressions</a>.If any entire ERE pattern matches some part of an input line excluding the terminating <newline>, the line shall be matched.A null ERE shall match every line.</dd><dt><b>-F</b></dt><dd>Match using fixed strings. Treat each pattern specified as a string instead of a regular expression. If an input line containsany of the patterns as a contiguous sequence of bytes, the line shall be matched. A null string shall match every line.</dd><dt><b>-c</b></dt><dd>Write only a count of selected lines to standard output.</dd><dt><b>-e </b> <i>pattern_list</i></dt><dd><br>Specify one or more patterns to be used during the search for input. The application shall ensure that patterns in<i>pattern_list</i> are separated by a <newline>. A null pattern can be specified by two adjacent <newline>s in<i>pattern_list</i>. Unless the <b>-E</b> or <b>-F</b> option is also specified, each pattern shall be treated as a BRE, asdescribed in the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap09.html#tag_09_03">Section9.3, Basic Regular Expressions</a>. Multiple <b>-e</b> and <b>-f</b> options shall be accepted by the <i>grep</i> utility. All ofthe specified patterns shall be used when matching lines, but the order of evaluation is unspecified.</dd><dt><b>-f </b> <i>pattern_file</i></dt><dd><br>Read one or more patterns from the file named by the pathname <i>pattern_file</i>. Patterns in <i>pattern_file</i> shall beterminated by a <newline>. A null pattern can be specified by an empty line in <i>pattern_file</i>. Unless the <b>-E</b> or<b>-F</b> option is also specified, each pattern shall be treated as a BRE, as described in the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap09.html#tag_09_03">Section 9.3, Basic Regular Expressions</a>.</dd><dt><b>-i</b></dt><dd>Perform pattern matching in searches without regard to case; see the Base Definitions volume of IEEE Std 1003.1-2001,<a href="../basedefs/xbd_chap09.html#tag_09_02">Section 9.2, Regular Expression General Requirements</a>.</dd><dt><b>-l</b></dt><dd>(The letter ell.) Write only the names of files containing selected lines to standard output. Pathnames shall be written onceper file searched. If the standard input is searched, a pathname of <tt>"(standard input)"</tt> shall be written, in the POSIXlocale. In other locales, <tt>"standard input"</tt> may be replaced by something more appropriate in those locales.</dd><dt><b>-n</b></dt><dd>Precede each output line by its relative line number in the file, each file starting at line 1. The line number counter shallbe reset for each file processed.</dd><dt><b>-q</b></dt><dd>Quiet. Nothing shall be written to the standard output, regardless of matching lines. Exit with zero status if an input line isselected.</dd><dt><b>-s</b></dt><dd>Suppress the error messages ordinarily written for nonexistent or unreadable files. Other error messages shall not besuppressed.</dd><dt><b>-v</b></dt><dd>Select lines not matching any of the specified patterns. If the <b>-v</b> option is not specified, selected lines shall bethose that match any of the specified patterns.</dd><dt><b>-x</b></dt><dd>Consider only input lines that use all characters in the line excluding the terminating <newline> to match an entirefixed string or regular expression to be matching lines.</dd></dl></blockquote><h4><a name="tag_04_63_05"></a>OPERANDS</h4><blockquote><p>The following operands shall be supported:</p><dl compact><dt><i>pattern_list</i></dt><dd>Specify one or more patterns to be used during the search for input. This operand shall be treated as if it were specified as<b>-e</b> <i>pattern_list</i>.</dd><dt><i>file</i></dt><dd>A pathname of a file to be searched for the patterns. If no <i>file</i> operands are specified, the standard input shall beused.</dd></dl></blockquote><h4><a name="tag_04_63_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_63_07"></a>INPUT FILES</h4><blockquote><p>The input files shall be text files.</p></blockquote><h4><a name="tag_04_63_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>grep</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_63_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_63_10"></a>STDOUT</h4><blockquote><p>If the <b>-l</b> option is in effect, and the <b>-q</b> option is not, the following shall be written for each file containingat least one selected input line:</p><pre><tt>"%s\n", <</tt><i>file</i><tt>></tt></pre><p>Otherwise, if more than one <i>file</i> argument appears, and <b>-q</b> is not specified, the <i>grep</i> utility shall prefixeach output line by:</p><pre><tt>"%s:", <</tt><i>file</i><tt>></tt></pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -