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

📄 grep.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>grep</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_890">&nbsp;</a>NAME</h4><blockquote>grep - search a file for a pattern</blockquote><h4><a name = "tag_001_014_891">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>grep <b>[</b> -E| -F<b>][</b> -c| -l| -q <b>][</b>-insvx<b>] </b>-e <i>pattern_list...</i><b>[</b>-f <i>pattern_file</i><b>]</b>...<b>[</b><i>file</i>...<b>]</b>grep <b>[</b> -E| -F<b>][</b> -c| -l| -q <b>][</b>-insvx<b>][</b>-e <i>pattern_list...</i>-f <i>pattern_file</i>...<b>[</b><i>file</i>...<b>]</b>grep <b>[</b> -E| -F<b>][</b> -c| -l| -q <b>][</b>-insvx<b>] </b><i>pattern_list</i><b>[</b><i>file</i>...<b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_892">&nbsp;</a>DESCRIPTION</h4><blockquote>The<i>grep</i>utility searches the input files,selecting lines matching one or more patterns;the types of patterns are controlled 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>'svalue consists of oneor more patterns separated bynewline characters;the<i>pattern_file</i>'scontents consist of one or more patterns terminated bynewline characters.By default, an input line will be selected if anypattern, treated as an entire basic regular expression (BRE) asdescribed in the <b>XBD</b> specification, <a href="../xbd/re.html#tag_007_003"><b>Basic Regular Expressions</b>&nbsp;</a> , matches any part of the line;a null BRE will match every line.By default,each selected input line will be written to the standard output.<p>Regular expression matching will be based on text lines.Since a newline characterseparates or terminates patterns (see the<b>-e</b>and<b>-f</b>options below), regular expressions cannot contain anewlinecharacter.Similarly, since patterns are matched againstindividual lines of the input, there is no way for a pattern tomatch a newline character found in the input.</blockquote><h4><a name = "tag_001_014_893">&nbsp;</a>OPTIONS</h4><blockquote>The<i>grep</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .<p>The following options are supported:<dl compact><dt><b>-E</b><dd>Match using extended regular expressions.Treat each pattern specifiedas an ERE, as described in the <b>XBD</b> specification, <a href="../xbd/re.html#tag_007_004"><b>Extended Regular Expressions</b>&nbsp;</a> .If any entire ERE pattern matches an input line, the line will be matched.A null ERE matches every line.<dt><b>-F</b><dd>Match using fixed strings.Treat each pattern specified as a string instead of a regular expression.If an input line contains any of the patterns as a contiguoussequence of bytes, the line will be matched.A null string matches every line.<dt><b>-c</b><dd>Write only a count of selected lines to standard output.<dt><b>-e&nbsp;</b><i>pattern_list</i><dd>Specify one or more patterns to be used during the search for input.Patterns in<i>pattern_list</i>must be separated by anewline character.A null pattern can be specified by two adjacentnewline characters in<i>pattern_list</i>.Unless the<b>-E</b>or<b>-F</b>option is also specified, each pattern will be treated as a BRE,as described in the <b>XBD</b> specification, <a href="../xbd/re.html#tag_007_003"><b>Basic Regular Expressions</b>&nbsp;</a> .Multiple<b>-e</b>and<b>-f</b>options are accepted by the<i>grep</i>utility.All of the specified patternsare used when matching lines, but the order of evaluationis unspecified.<dt><b>-f&nbsp;</b><i>pattern_file</i><dd>Read one or more patterns from the file named by thepathname<i>pattern_file.</i>Patterns in<i>pattern_file</i>are terminated by anewline character.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 alsospecified, each pattern will be treated as a BRE, as described inthe <b>XBD</b> specification, <a href="../xbd/re.html#tag_007_003"><b>Basic Regular Expressions</b>&nbsp;</a> .<dt><b>-i</b><dd>Perform pattern matching in searches without regard to case.See the <b>XBD</b> specification, <a href="../xbd/re.html#tag_007_002"><b>Regular Expression General Requirements</b>&nbsp;</a> .<dt><b>-l</b><dd>(The letter ell.)Write only the names of files containing selected lines to standard output.Pathnames are written once per file searched.If the standard input is searched, a pathname of<b>(standard&nbsp;input)</b>will be written, in the POSIX locale.In other locales,<b>standard input</b>may be replaced by something more appropriate in those locales.<dt><b>-n</b><dd>Precede each output line by its relative line number in the file,each file starting at line 1.The line number counter will be reset for each file processed.<dt><b>-q</b><dd>Quiet.Do not write anything to the standard output,regardless of matching lines.Exit with zero statusif an input line is selected.<dt><b>-s</b><dd>Suppress the error messages ordinarily written for non-existentor unreadable files.Other error messages will not be suppressed.<dt><b>-v</b><dd>Select lines not matching any of the specified patterns.If the<b>-v</b>option is not specified, selected lines will be those that match any of thespecified patterns.<dt><b>-x</b><dd>Consider only input lines that use all characters inthe line to match an entire fixed string orregular expression to be matching lines.</dl></blockquote><h4><a name = "tag_001_014_894">&nbsp;</a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><i>pattern</i><dd>Specify one or more patterns to be used during thesearch for input.This operand is treated as if it were specified as<b>-e</b>&nbsp;<i>pattern_list</i>.<dt><i>file</i><dd>A pathname of a file to be searched for the patterns.If no<i>file</i>operands are specified,the standard input will be used.</dl></blockquote><h4><a name = "tag_001_014_895">&nbsp;</a>STDIN</h4><blockquote>The standard input will be used only if no<i>file</i>operands are specified.See the INPUT FILES section.</blockquote><h4><a name = "tag_001_014_896">&nbsp;</a>INPUT FILES</h4><blockquote>The input files must be text files.</blockquote><h4><a name = "tag_001_014_897">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>grep</i>:<dl compact><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 error.<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_898">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_899">&nbsp;</a>STDOUT</h4><blockquote>If the<b>-l</b>option is in effect,and the<b>-q</b>option is not, the following will be writtenfor each file containing at least one selected input line:<p><code><tt>"%s\n"</tt>, <i>file</i></code><p>Otherwise, if more than one<i>file</i>argument appears,and<b>-q</b>is not specified,the<i>grep</i>utility will prefix each output line by:<p><code><tt>"%s:"</tt>, <i>file</i></code><p>The remainder of each output line depends on the other options specified:<ul><p><li>If the<b>-c</b>option is in effect, the remainder of each output line will contain:<p><code><tt>"%d\n"</tt>, &lt;<i>count</i>&gt;</code><p><li>Otherwise, if<b>-c</b>is not in effect and the<b>-n</b>option is in effect, the followingwill be written to standard output:<p><code><tt>"%d:"</tt>, &lt;<i>line number</i>&gt;</code><p><li>Finally, the following will be written to standard output:<p><code><tt>"%s"</tt>, &lt;<i>selected-line contents</i>&gt;</code><p></ul></blockquote><h4><a name = "tag_001_014_900">&nbsp;</a>STDERR</h4><blockquote>Used only for diagnostic messages.</blockquote><h4><a name = "tag_001_014_901">&nbsp;</a>OUTPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_902">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_903">&nbsp;</a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>One or more lines were selected.<dt>1<dd>No lines were selected.<dt>&gt;1<dd>An error occurred.</dl></blockquote><h4><a name = "tag_001_014_904">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>If the<b>-q</b>option is specified, the exit status will be zero ifan input line is selected, even if an error was detected.Otherwise, default actions will be performed.</blockquote><h4><a name = "tag_001_014_905">&nbsp;</a>APPLICATION USAGE</h4><blockquote>Care should be taken when using characters in<i>pattern_list</i>that may also be meaningful to the command interpreter.It is safest to enclose the entire<i>pattern_list</i>argument in single quotes:<pre><code>'...'</code></pre><p>The<b>-e</b>&nbsp;<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 moreconvenient to provide multiple patterns as separate arguments.<p>Multiple<b>-e</b>and<b>-f</b>options are accepted and<i>grep</i>will use all of the patternsit is given while matching input text lines.(Note that the order of evaluation is not specified.If an implementationfinds a null string as a pattern, it is allowed to use thatpattern first, matching every line, and effectively ignoreany other patterns.)<p>The<b>-q</b>option provides a means of easily determining whether or nota 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 tosupply as arguments (because it will exit zero if it finds amatch even if<i>grep</i>detected an access or read error on earlier file operands).</blockquote><h4><a name = "tag_001_014_906">&nbsp;</a>EXAMPLES</h4><blockquote><ol><p><li>To find all uses of the wordPosix(in any case) in file<b>text.mm</b>and write with line numbers:<pre><code>grep -i -n posix text.mm</code></pre><p><li>To find all empty lines in the standard input:<pre><code>grep ^$</code></pre><p>or:<pre><code>grep -v .</code></pre><br><p><li>Both of the following commands print all lines containing strings<b>abc</b>or<b>def</b>or both:<pre><code>grep -E 'abcdef'grep -F 'abcdef'</code></pre><p><li>Both of the following commands print all lines matching exactly<b>abc</b>or<b>def</b>:<pre><code>grep -E '^abc$^def$'grep -F -x 'abcdef'</code></pre><p></ol></blockquote><h4><a name = "tag_001_014_907">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_908">&nbsp;</a>SEE ALSO</h4><blockquote><i><a href="sed.html">sed</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 + -