CVSROOT: /webcvs/grep Module name: grep Changes by: Jim Meyering <meyering> 10/09/21 06:07:07
Index: grep.html =================================================================== RCS file: /webcvs/grep/grep/manual/grep.html,v retrieving revision 1.5 retrieving revision 1.6 diff -u -b -r1.5 -r1.6 --- grep.html 2 Apr 2010 10:26:52 -0000 1.5 +++ grep.html 21 Sep 2010 06:07:05 -0000 1.6 @@ -1,8 +1,8 @@ <html lang="en"> <head> -<title>GNU Grep 2.6.3</title> +<title>GNU Grep 2.7</title> <meta http-equiv="Content-Type" content="text/html"> -<meta name="description" content="GNU Grep 2.6.3"> +<meta name="description" content="GNU Grep 2.7"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="top" href="#Top"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> @@ -33,7 +33,7 @@ --></style> </head> <body> -<h1 class="settitle">GNU Grep 2.6.3</h1> +<h1 class="settitle">GNU Grep 2.7</h1> <div class="contents"> <h2>Table of Contents</h2> <ul> @@ -91,7 +91,7 @@ <p><samp><span class="command">grep</span></samp> prints lines that match a pattern. - <p>This manual is for version 2.6.3 of GNU Grep. + <p>This manual is for version 2.7 of GNU Grep. <p>This manual is for <samp><span class="command">grep</span></samp>, a pattern matching engine. @@ -786,12 +786,8 @@ by default, such options are permuted to the front of the operand list and are treated as options. -Also, -<span class="sc">posix.2</span> requires that unrecognized options be diagnosed as “illegal”, -but since they are not really against the law the default -is to diagnose them as “invalid”. -<code>POSIXLY_CORRECT</code> also disables <code>_</code><var>N</var><code>_GNU_nonoption_argv_flags_</code>, -described below. +Also, <code>POSIXLY_CORRECT</code> disables special handling of an +invalid bracket expression. See <a href="#invalid_002dbracket_002dexpr">invalid-bracket-expr</a>. <br><dt><samp><span class="env">_</span><var>N</var><span class="env">_GNU_nonoption_argv_flags_</span></samp><dd><a name="index-g_t_005f_0040var_007bN_007d_005fGNU_005fnonoption_005fargv_005fflags_005f-_0040r_007benvironment-variable_007d-165"></a>(Here <var>N</var> is <samp><span class="command">grep</span></samp>'s numeric process ID.) If the <var>i</var>th character of this environment variable's value is ‘<samp><span class="samp">1</span></samp>’, @@ -1037,6 +1033,7 @@ <br><dt>‘<samp><span class="samp">[:space:]</span></samp>’<dd><a name="index-space-_0040r_007bcharacter-class_007d-231"></a><a name="index-space-characters-232"></a><a name="index-whitespace-characters-233"></a>Space characters: tab, newline, vertical tab, form feed, carriage return, and space. +See <a href="#Usage">Usage</a>, for more discussion of matching newlines. <br><dt>‘<samp><span class="samp">[:upper:]</span></samp>’<dd><a name="index-upper-_0040r_007bcharacter-class_007d-234"></a><a name="index-upper_002dcase-letters-235"></a>Upper-case letters: <code>A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</code>. @@ -1052,6 +1049,12 @@ part of the symbolic names, and must be included in addition to the brackets delimiting the bracket expression.) + <p><a name="invalid_002dbracket_002dexpr"></a>If you mistakenly omit the outer brackets, and search for say, ‘<samp><span class="samp">[:upper:]</span></samp>’, +GNU <samp><span class="command">grep</span></samp> prints a diagnostic and exits with status 2, on +the assumption that you did not intend to search for the nominally +equivalent regular expression: ‘<samp><span class="samp">[:epru]</span></samp>’. +Set the <code>POSIXLY_CORRECT</code> environment variable to disable this feature. + <p>Most meta-characters lose their special meaning inside bracket expressions. <dl> @@ -1109,6 +1112,10 @@ <br><dt>‘<samp><span class="samp">‘</span><samp><span class="samp">\W</span></samp><span class="samp">’</span></samp>’<dd>Match non-word constituent, it is a synonym for ‘<samp><span class="samp">[^[:alnum:]]</span></samp>’. + <br><dt>‘<samp><span class="samp">‘</span><samp><span class="samp">\s</span></samp><span class="samp">’</span></samp>’<dd>Match whitespace, it is a synonym for ‘<samp><span class="samp">[[:space:]]</span></samp>’. + + <br><dt>‘<samp><span class="samp">‘</span><samp><span class="samp">\S</span></samp><span class="samp">’</span></samp>’<dd>Match non-whitespace, it is a synonym for ‘<samp><span class="samp">[^[:space:]]</span></samp>’. + </dl> <p>For example, ‘<samp><span class="samp">\brat\b</span></samp>’ matches the separate word ‘<samp><span class="samp">rat</span></samp>’, @@ -1362,7 +1369,29 @@ as there is no ‘<samp><span class="samp">aa</span></samp>’ in the input, so the ‘<samp><span class="samp">\1</span></samp>’ in the second alternate has nothing to refer back to, meaning it will never match anything. (The second alternate in this example can only match -if the first alternate has matched – making the second one superfluous.) +if the first alternate has matched—making the second one superfluous.) + + <li>How can I match across lines? + + <p>Standard grep cannot do this, as it is fundamentally line-based. +Therefore, merely using the <code>[:space:]</code> character class does not +match newlines in the way you might expect. However, if your grep is +compiled with Perl patterns enabled, the Perl ‘<samp><span class="samp">s</span></samp>’ +modifier (which makes <code>.</code> match newlines) can be used: + + <pre class="example"> printf 'foo\nbar\n' | grep -P '(?s)foo.*?bar' +</pre> + <p>With the GNU <samp><span class="command">grep</span></samp> option <code>-z</code> (see <a href="#File-and-Directory-Selection">File and Directory Selection</a>), the input is terminated by null bytes. Thus, +you can match newlines in the input, but the output will be the whole +file, so this is really only useful to determine if the pattern is +present: + + <pre class="example"> printf 'foo\nbar\n' | grep -z -q 'foo[[:space:]]\+bar' +</pre> + <p>Failing either of those options, you need to transform the input +before giving it to <samp><span class="command">grep</span></samp>, or turn to <samp><span class="command">awk</span></samp>, +<samp><span class="command">sed</span></samp>, <samp><span class="command">perl</span></samp>, or many other utilities that are +designed to operate across lines. <li>What do <samp><span class="command">grep</span></samp>, <samp><span class="command">fgrep</span></samp>, and <samp><span class="command">egrep</span></samp> stand for?
