grep-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Changes to grep/manual/html_node/Usage.html,v


From: Jim Meyering
Subject: Changes to grep/manual/html_node/Usage.html,v
Date: Wed, 22 Mar 2023 22:55:26 -0400 (EDT)

CVSROOT:        /webcvs/grep
Module name:    grep
Changes by:     Jim Meyering <meyering> 23/03/22 22:55:22

Index: html_node/Usage.html
===================================================================
RCS file: /webcvs/grep/grep/manual/html_node/Usage.html,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- html_node/Usage.html        3 Sep 2022 19:33:14 -0000       1.33
+++ html_node/Usage.html        23 Mar 2023 02:55:21 -0000      1.34
@@ -1,11 +1,11 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
+<!DOCTYPE html>
 <html>
-<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
+<!-- Created by GNU Texinfo 7.0dev, https://www.gnu.org/software/texinfo/ -->
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <!-- This manual is for grep, a pattern matching engine.
 
-Copyright (C) 1999-2002, 2005, 2008-2022 Free Software Foundation,
+Copyright © 1999-2002, 2005, 2008-2023 Free Software Foundation,
 Inc.
 
 Permission is granted to copy, distribute and/or modify this document
@@ -14,10 +14,10 @@
 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
 Texts.  A copy of the license is included in the section entitled
 "GNU Free Documentation License". -->
-<title>Usage (GNU Grep 3.8)</title>
+<title>Usage (GNU Grep 3.10)</title>
 
-<meta name="description" content="Usage (GNU Grep 3.8)">
-<meta name="keywords" content="Usage (GNU Grep 3.8)">
+<meta name="description" content="Usage (GNU Grep 3.10)">
+<meta name="keywords" content="Usage (GNU Grep 3.10)">
 <meta name="resource-type" content="document">
 <meta name="distribution" content="global">
 <meta name="Generator" content="makeinfo">
@@ -31,21 +31,9 @@
 <link href="Regular-Expressions.html" rel="prev" title="Regular Expressions">
 <style type="text/css">
 <!--
-a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
-a.summary-letter {text-decoration: none}
-blockquote.indentedblock {margin-right: 0em}
-div.display {margin-left: 3.2em}
+a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
 div.example {margin-left: 3.2em}
-kbd {font-style: oblique}
-pre.display {font-family: inherit}
-pre.format {font-family: inherit}
-pre.menu-comment {font-family: serif}
-pre.menu-preformatted {font-family: serif}
-span.nolinebreak {white-space: nowrap}
-span.roman {font-family: initial; font-weight: normal}
-span.sansserif {font-family: sans-serif; font-weight: normal}
-span:hover a.copiable-anchor {visibility: visible}
-ul.no-bullet {list-style: none}
+span:hover a.copiable-link {visibility: visible}
 -->
 </style>
 <link rel="stylesheet" type="text/css" 
href="https://www.gnu.org/software/gnulib/manual.css";>
@@ -54,317 +42,317 @@
 </head>
 
 <body lang="en">
-<div class="chapter" id="Usage">
-<div class="header">
+<div class="chapter-level-extent" id="Usage">
+<div class="nav-panel">
 <p>
 Next: <a href="Performance.html" accesskey="n" rel="next">Performance</a>, 
Previous: <a href="Regular-Expressions.html" accesskey="p" rel="prev">Regular 
Expressions</a>, Up: <a href="index.html" accesskey="u" rel="up">grep</a> 
&nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" 
rel="contents">Contents</a>][<a href="Index.html" title="Index" 
rel="index">Index</a>]</p>
 </div>
 <hr>
-<span id="Usage-1"></span><h2 class="chapter">4 Usage</h2>
+<h2 class="chapter" id="Usage-1"><span>4 Usage<a class="copiable-link" 
href="#Usage-1"> &para;</a></span></h2>
 
-<span id="index-usage_002c-examples"></span>
-<p>Here is an example command that invokes GNU <code>grep</code>:
+<a class="index-entry-id" id="index-usage_002c-examples"></a>
+<p>Here is an example command that invokes GNU <code 
class="command">grep</code>:
 </p>
 <div class="example">
-<pre class="example">grep -i 'hello.*world' menu.h main.c
+<pre class="example-preformatted">grep -i 'hello.*world' menu.h main.c
 </pre></div>
 
-<p>This lists all lines in the files <samp>menu.h</samp> and 
<samp>main.c</samp> that
-contain the string &lsquo;<samp>hello</samp>&rsquo; followed by the string 
&lsquo;<samp>world</samp>&rsquo;;
-this is because &lsquo;<samp>.*</samp>&rsquo; matches zero or more characters 
within a line.
-See <a href="Regular-Expressions.html">Regular Expressions</a>.
-The <samp>-i</samp> option causes <code>grep</code>
-to ignore case, causing it to match the line &lsquo;<samp>Hello, 
world!</samp>&rsquo;, which
+<p>This lists all lines in the files <samp class="file">menu.h</samp> and 
<samp class="file">main.c</samp> that
+contain the string &lsquo;<samp class="samp">hello</samp>&rsquo; followed by 
the string &lsquo;<samp class="samp">world</samp>&rsquo;;
+this is because &lsquo;<samp class="samp">.*</samp>&rsquo; matches zero or 
more characters within a line.
+See <a class="xref" href="Regular-Expressions.html">Regular Expressions</a>.
+The <samp class="option">-i</samp> option causes <code 
class="command">grep</code>
+to ignore case, causing it to match the line &lsquo;<samp class="samp">Hello, 
world!</samp>&rsquo;, which
 it would not otherwise match.
 </p>
 <p>Here is a more complex example,
 showing the location and contents of any line
-containing &lsquo;<samp>f</samp>&rsquo; and ending in 
&lsquo;<samp>.c</samp>&rsquo;,
+containing &lsquo;<samp class="samp">f</samp>&rsquo; and ending in 
&lsquo;<samp class="samp">.c</samp>&rsquo;,
 within all files in the current directory whose names
-start with non-&lsquo;<samp>.</samp>&rsquo;, contain 
&lsquo;<samp>g</samp>&rsquo;, and end in &lsquo;<samp>.h</samp>&rsquo;.
-The <samp>-n</samp> option outputs line numbers, the <samp>--</samp> argument
+start with non-&lsquo;<samp class="samp">.</samp>&rsquo;, contain &lsquo;<samp 
class="samp">g</samp>&rsquo;, and end in &lsquo;<samp 
class="samp">.h</samp>&rsquo;.
+The <samp class="option">-n</samp> option outputs line numbers, the <samp 
class="option">--</samp> argument
 treats any later arguments as file names not options even if
-<code>*g*.h</code> expands to a file name that starts with 
&lsquo;<samp>-</samp>&rsquo;,
-and the empty file <samp>/dev/null</samp> causes file names to be output
-even if only one file name happens to be of the form 
&lsquo;<samp>*g*.h</samp>&rsquo;.
+<code class="code">*g*.h</code> expands to a file name that starts with 
&lsquo;<samp class="samp">-</samp>&rsquo;,
+and the empty file <samp class="file">/dev/null</samp> causes file names to be 
output
+even if only one file name happens to be of the form &lsquo;<samp 
class="samp">*g*.h</samp>&rsquo;.
 </p>
 <div class="example">
-<pre class="example">grep -n -- 'f.*\.c$' *g*.h /dev/null
+<pre class="example-preformatted">grep -n -- 'f.*\.c$' *g*.h /dev/null
 </pre></div>
 
 <p>Note that the regular expression syntax used in the pattern differs
 from the globbing syntax that the shell uses to match file names.
 </p>
-<p>See <a href="Invoking.html">Invoking <code>grep</code></a>, for more 
details about
-how to invoke <code>grep</code>.
+<p>See <a class="xref" href="Invoking.html">Invoking <code 
class="command">grep</code></a>, for more details about
+how to invoke <code class="command">grep</code>.
 </p>
-<span id="index-using-grep_002c-Q_0026A"></span>
-<span id="index-FAQ-about-grep-usage"></span>
-<p>Here are some common questions and answers about <code>grep</code> usage.
+<a class="index-entry-id" id="index-using-grep_002c-Q_0026A"></a>
+<a class="index-entry-id" id="index-FAQ-about-grep-usage"></a>
+<p>Here are some common questions and answers about <code 
class="command">grep</code> usage.
 </p>
-<ol>
+<ol class="enumerate">
 <li> How can I list just the names of matching files?
 
 <div class="example">
-<pre class="example">grep -l 'main' test-*.c
+<pre class="example-preformatted">grep -l 'main' test-*.c
 </pre></div>
 
-<p>lists names of &lsquo;<samp>test-*.c</samp>&rsquo; files in the current 
directory whose contents
-mention &lsquo;<samp>main</samp>&rsquo;.
+<p>lists names of &lsquo;<samp class="samp">test-*.c</samp>&rsquo; files in 
the current directory whose contents
+mention &lsquo;<samp class="samp">main</samp>&rsquo;.
 </p>
 </li><li> How do I search directories recursively?
 
 <div class="example">
-<pre class="example">grep -r 'hello' /home/gigi
+<pre class="example-preformatted">grep -r 'hello' /home/gigi
 </pre></div>
 
-<p>searches for &lsquo;<samp>hello</samp>&rsquo; in all files
-under the <samp>/home/gigi</samp> directory.
+<p>searches for &lsquo;<samp class="samp">hello</samp>&rsquo; in all files
+under the <samp class="file">/home/gigi</samp> directory.
 For more control over which files are searched,
-use <code>find</code> and <code>grep</code>.
+use <code class="command">find</code> and <code class="command">grep</code>.
 For example, the following command searches only C files:
 </p>
 <div class="example">
-<pre class="example">find /home/gigi -name '*.c' ! -type d \
+<pre class="example-preformatted">find /home/gigi -name '*.c' ! -type d \
   -exec grep -H 'hello' '{}' +
 </pre></div>
 
 <p>This differs from the command:
 </p>
 <div class="example">
-<pre class="example">grep -H 'hello' /home/gigi/*.c
+<pre class="example-preformatted">grep -H 'hello' /home/gigi/*.c
 </pre></div>
 
-<p>which merely looks for &lsquo;<samp>hello</samp>&rsquo; in non-hidden C 
files in
-<samp>/home/gigi</samp> whose names end in &lsquo;<samp>.c</samp>&rsquo;.
-The <code>find</code> command line above is more similar to the command:
+<p>which merely looks for &lsquo;<samp class="samp">hello</samp>&rsquo; in 
non-hidden C files in
+<samp class="file">/home/gigi</samp> whose names end in &lsquo;<samp 
class="samp">.c</samp>&rsquo;.
+The <code class="command">find</code> command line above is more similar to 
the command:
 </p>
 <div class="example">
-<pre class="example">grep -r --include='*.c' 'hello' /home/gigi
+<pre class="example-preformatted">grep -r --include='*.c' 'hello' /home/gigi
 </pre></div>
 
-</li><li> What if a pattern or file has a leading &lsquo;<samp>-</samp>&rsquo;?
+</li><li> What if a pattern or file has a leading &lsquo;<samp 
class="samp">-</samp>&rsquo;?
 For example:
 
 <div class="example">
-<pre class="example">grep &quot;$pattern&quot; *
+<pre class="example-preformatted">grep &quot;$pattern&quot; *
 </pre></div>
 
-<p>can behave unexpectedly if the value of &lsquo;<samp>pattern</samp>&rsquo; 
begins with &lsquo;<samp>-</samp>&rsquo;,
-or if the &lsquo;<samp>*</samp>&rsquo; expands to a file name with leading 
&lsquo;<samp>-</samp>&rsquo;.
-To avoid the problem, you can use <samp>-e</samp> for patterns and leading
-&lsquo;<samp>./</samp>&rsquo; for files:
+<p>can behave unexpectedly if the value of &lsquo;<samp 
class="samp">pattern</samp>&rsquo; begins with &lsquo;<samp 
class="samp">-</samp>&rsquo;,
+or if the &lsquo;<samp class="samp">*</samp>&rsquo; expands to a file name 
with leading &lsquo;<samp class="samp">-</samp>&rsquo;.
+To avoid the problem, you can use <samp class="option">-e</samp> for patterns 
and leading
+&lsquo;<samp class="samp">./</samp>&rsquo; for files:
 </p>
 <div class="example">
-<pre class="example">grep -e &quot;$pattern&quot; ./*
+<pre class="example-preformatted">grep -e &quot;$pattern&quot; ./*
 </pre></div>
 
 <p>searches for all lines matching the pattern in all the working
-directory&rsquo;s files whose names do not begin with 
&lsquo;<samp>.</samp>&rsquo;.
-Without the <samp>-e</samp>, <code>grep</code> might treat the pattern as an
-option if it begins with &lsquo;<samp>-</samp>&rsquo;.  Without the 
&lsquo;<samp>./</samp>&rsquo;, there might
-be similar problems with file names beginning with 
&lsquo;<samp>-</samp>&rsquo;.
+directory&rsquo;s files whose names do not begin with &lsquo;<samp 
class="samp">.</samp>&rsquo;.
+Without the <samp class="option">-e</samp>, <code class="command">grep</code> 
might treat the pattern as an
+option if it begins with &lsquo;<samp class="samp">-</samp>&rsquo;.  Without 
the &lsquo;<samp class="samp">./</samp>&rsquo;, there might
+be similar problems with file names beginning with &lsquo;<samp 
class="samp">-</samp>&rsquo;.
 </p>
-<p>Alternatively, you can use &lsquo;<samp>--</samp>&rsquo; before the pattern 
and file names:
+<p>Alternatively, you can use &lsquo;<samp class="samp">--</samp>&rsquo; 
before the pattern and file names:
 </p>
 <div class="example">
-<pre class="example">grep -- &quot;$pattern&quot; *
+<pre class="example-preformatted">grep -- &quot;$pattern&quot; *
 </pre></div>
 
-<p>This also fixes the problem, except that if there is a file named 
&lsquo;<samp>-</samp>&rsquo;,
-<code>grep</code> misinterprets the &lsquo;<samp>-</samp>&rsquo; as standard 
input.
+<p>This also fixes the problem, except that if there is a file named 
&lsquo;<samp class="samp">-</samp>&rsquo;,
+<code class="command">grep</code> misinterprets the &lsquo;<samp 
class="samp">-</samp>&rsquo; as standard input.
 </p>
 </li><li> Suppose I want to search for a whole word, not a part of a word?
 
 <div class="example">
-<pre class="example">grep -w 'hello' test*.log
+<pre class="example-preformatted">grep -w 'hello' test*.log
 </pre></div>
 
-<p>searches only for instances of &lsquo;<samp>hello</samp>&rsquo; that are 
entire words;
-it does not match &lsquo;<samp>Othello</samp>&rsquo;.
-For more control, use &lsquo;<samp>\&lt;</samp>&rsquo; and
-&lsquo;<samp>\&gt;</samp>&rsquo; to match the start and end of words.
+<p>searches only for instances of &lsquo;<samp 
class="samp">hello</samp>&rsquo; that are entire words;
+it does not match &lsquo;<samp class="samp">Othello</samp>&rsquo;.
+For more control, use &lsquo;<samp class="samp">\&lt;</samp>&rsquo; and
+&lsquo;<samp class="samp">\&gt;</samp>&rsquo; to match the start and end of 
words.
 For example:
 </p>
 <div class="example">
-<pre class="example">grep 'hello\&gt;' test*.log
+<pre class="example-preformatted">grep 'hello\&gt;' test*.log
 </pre></div>
 
-<p>searches only for words ending in &lsquo;<samp>hello</samp>&rsquo;, so it 
matches the word
-&lsquo;<samp>Othello</samp>&rsquo;.
+<p>searches only for words ending in &lsquo;<samp 
class="samp">hello</samp>&rsquo;, so it matches the word
+&lsquo;<samp class="samp">Othello</samp>&rsquo;.
 </p>
 </li><li> How do I output context around the matching lines?
 
 <div class="example">
-<pre class="example">grep -C 2 'hello' test*.log
+<pre class="example-preformatted">grep -C 2 'hello' test*.log
 </pre></div>
 
 <p>prints two lines of context around each matching line.
 </p>
-</li><li> How do I force <code>grep</code> to print the name of the file?
+</li><li> How do I force <code class="command">grep</code> to print the name 
of the file?
 
-<p>Append <samp>/dev/null</samp>:
+<p>Append <samp class="file">/dev/null</samp>:
 </p>
 <div class="example">
-<pre class="example">grep 'eli' /etc/passwd /dev/null
+<pre class="example-preformatted">grep 'eli' /etc/passwd /dev/null
 </pre></div>
 
 <p>gets you:
 </p>
 <div class="example">
-<pre class="example">/etc/passwd:eli:x:2098:1000:Eli Smith:/home/eli:/bin/bash
+<pre class="example-preformatted">/etc/passwd:eli:x:2098:1000:Eli 
Smith:/home/eli:/bin/bash
 </pre></div>
 
-<p>Alternatively, use <samp>-H</samp>, which is a GNU extension:
+<p>Alternatively, use <samp class="option">-H</samp>, which is a GNU extension:
 </p>
 <div class="example">
-<pre class="example">grep -H 'eli' /etc/passwd
+<pre class="example-preformatted">grep -H 'eli' /etc/passwd
 </pre></div>
 
-</li><li> Why do people use strange regular expressions on <code>ps</code> 
output?
+</li><li> Why do people use strange regular expressions on <code 
class="command">ps</code> output?
 
 <div class="example">
-<pre class="example">ps -ef | grep '[c]ron'
+<pre class="example-preformatted">ps -ef | grep '[c]ron'
 </pre></div>
 
 <p>If the pattern had been written without the square brackets, it would
-have matched not only the <code>ps</code> output line for <code>cron</code>,
-but also the <code>ps</code> output line for <code>grep</code>.
+have matched not only the <code class="command">ps</code> output line for 
<code class="command">cron</code>,
+but also the <code class="command">ps</code> output line for <code 
class="command">grep</code>.
 Note that on some platforms,
-<code>ps</code> limits the output to the width of the screen;
-<code>grep</code> does not have any limit on the length of a line
+<code class="command">ps</code> limits the output to the width of the screen;
+<code class="command">grep</code> does not have any limit on the length of a 
line
 except the available memory.
 </p>
-</li><li> Why does <code>grep</code> report &ldquo;Binary file matches&rdquo;?
+</li><li> Why does <code class="command">grep</code> report &ldquo;Binary file 
matches&rdquo;?
 
-<p>If <code>grep</code> listed all matching &ldquo;lines&rdquo; from a binary 
file, it
+<p>If <code class="command">grep</code> listed all matching 
&ldquo;lines&rdquo; from a binary file, it
 would probably generate output that is not useful, and it might even
 muck up your display.
-So GNU <code>grep</code> suppresses output from
+So GNU <code class="command">grep</code> suppresses output from
 files that appear to be binary files.
-To force GNU <code>grep</code>
+To force GNU <code class="command">grep</code>
 to output lines even from files that appear to be binary, use the
-<samp>-a</samp> or &lsquo;<samp>--binary-files=text</samp>&rsquo; option.
+<samp class="option">-a</samp> or &lsquo;<samp 
class="samp">--binary-files=text</samp>&rsquo; option.
 To eliminate the
-&ldquo;Binary file matches&rdquo; messages, use the <samp>-I</samp> or
-&lsquo;<samp>--binary-files=without-match</samp>&rsquo; option.
+&ldquo;Binary file matches&rdquo; messages, use the <samp 
class="option">-I</samp> or
+&lsquo;<samp class="samp">--binary-files=without-match</samp>&rsquo; option.
 </p>
-</li><li> Why doesn&rsquo;t &lsquo;<samp>grep -lv</samp>&rsquo; print 
non-matching file names?
+</li><li> Why doesn&rsquo;t &lsquo;<samp class="samp">grep -lv</samp>&rsquo; 
print non-matching file names?
 
-<p>&lsquo;<samp>grep -lv</samp>&rsquo; lists the names of all files containing 
one or more
+<p>&lsquo;<samp class="samp">grep -lv</samp>&rsquo; lists the names of all 
files containing one or more
 lines that do not match.
 To list the names of all files that contain no
-matching lines, use the <samp>-L</samp> or <samp>--files-without-match</samp>
+matching lines, use the <samp class="option">-L</samp> or <samp 
class="option">--files-without-match</samp>
 option.
 </p>
-</li><li> I can do &ldquo;OR&rdquo; with &lsquo;<samp>|</samp>&rsquo;, but 
what about &ldquo;AND&rdquo;?
+</li><li> I can do &ldquo;OR&rdquo; with &lsquo;<samp 
class="samp">|</samp>&rsquo;, but what about &ldquo;AND&rdquo;?
 
 <div class="example">
-<pre class="example">grep 'paul' /etc/motd | grep 'franc,ois'
+<pre class="example-preformatted">grep 'paul' /etc/motd | grep 'franc,ois'
 </pre></div>
 
-<p>finds all lines that contain both &lsquo;<samp>paul</samp>&rsquo; and 
&lsquo;<samp>franc,ois</samp>&rsquo;.
+<p>finds all lines that contain both &lsquo;<samp 
class="samp">paul</samp>&rsquo; and &lsquo;<samp 
class="samp">franc,ois</samp>&rsquo;.
 </p>
 </li><li> Why does the empty pattern match every input line?
 
-<p>The <code>grep</code> command searches for lines that contain strings
+<p>The <code class="command">grep</code> command searches for lines that 
contain strings
 that match a pattern.  Every line contains the empty string, so an
-empty pattern causes <code>grep</code> to find a match on each line.  It
-is not the only such pattern: &lsquo;<samp>^</samp>&rsquo;, 
&lsquo;<samp>$</samp>&rsquo;, and many
-other patterns cause <code>grep</code> to match every line.
-</p>
-<p>To match empty lines, use the pattern &lsquo;<samp>^$</samp>&rsquo;.  To 
match blank
-lines, use the pattern &lsquo;<samp>^[[:blank:]]*$</samp>&rsquo;.  To match no 
lines at
-all, use an extended regular expression like &lsquo;<samp>a^</samp>&rsquo; or 
&lsquo;<samp>$a</samp>&rsquo;.
+empty pattern causes <code class="command">grep</code> to find a match on each 
line.  It
+is not the only such pattern: &lsquo;<samp class="samp">^</samp>&rsquo;, 
&lsquo;<samp class="samp">$</samp>&rsquo;, and many
+other patterns cause <code class="command">grep</code> to match every line.
+</p>
+<p>To match empty lines, use the pattern &lsquo;<samp 
class="samp">^$</samp>&rsquo;.  To match blank
+lines, use the pattern &lsquo;<samp class="samp">^[[:blank:]]*$</samp>&rsquo;. 
 To match no lines at
+all, use an extended regular expression like &lsquo;<samp 
class="samp">a^</samp>&rsquo; or &lsquo;<samp class="samp">$a</samp>&rsquo;.
 To match every line, a portable script should use a pattern like
-&lsquo;<samp>^</samp>&rsquo; instead of the empty pattern, as POSIX does not 
specify the
+&lsquo;<samp class="samp">^</samp>&rsquo; instead of the empty pattern, as 
POSIX does not specify the
 behavior of the empty pattern.
 </p>
 </li><li> How can I search in both standard input and in files?
 
-<p>Use the special file name &lsquo;<samp>-</samp>&rsquo;:
+<p>Use the special file name &lsquo;<samp class="samp">-</samp>&rsquo;:
 </p>
 <div class="example">
-<pre class="example">cat /etc/passwd | grep 'alain' - /etc/motd
+<pre class="example-preformatted">cat /etc/passwd | grep 'alain' - /etc/motd
 </pre></div>
 
-</li><li> Why can&rsquo;t I combine the shell&rsquo;s &lsquo;<samp>set 
-e</samp>&rsquo; with <code>grep</code>?
+</li><li> Why can&rsquo;t I combine the shell&rsquo;s &lsquo;<samp 
class="samp">set -e</samp>&rsquo; with <code class="command">grep</code>?
 
-<p>The <code>grep</code> command follows the convention of programs like
-<code>cmp</code> and <code>diff</code> where an exit status of 1 is not an
-error.  The shell command &lsquo;<samp>set -e</samp>&rsquo; causes the shell 
to exit if
+<p>The <code class="command">grep</code> command follows the convention of 
programs like
+<code class="command">cmp</code> and <code class="command">diff</code> where 
an exit status of 1 is not an
+error.  The shell command &lsquo;<samp class="samp">set -e</samp>&rsquo; 
causes the shell to exit if
 any subcommand exits with nonzero status, and this will cause the
-shell to exit merely because <code>grep</code> selected no lines,
+shell to exit merely because <code class="command">grep</code> selected no 
lines,
 which is ordinarily not what you want.
 </p>
-<p>There is a related problem with Bash&rsquo;s <code>set -e -o 
pipefail</code>.
-Since <code>grep</code> does not always read all its input, a command
-outputting to a pipe read by <code>grep</code> can fail when
-<code>grep</code> exits before reading all its input, and the command&rsquo;s
+<p>There is a related problem with Bash&rsquo;s <code class="command">set -e 
-o pipefail</code>.
+Since <code class="command">grep</code> does not always read all its input, a 
command
+outputting to a pipe read by <code class="command">grep</code> can fail when
+<code class="command">grep</code> exits before reading all its input, and the 
command&rsquo;s
 failure can cause Bash to exit.
 </p>
 </li><li> Why is this back-reference failing?
 
 <div class="example">
-<pre class="example">echo 'ba' | grep -E '(a)\1|b\1'
+<pre class="example-preformatted">echo 'ba' | grep -E '(a)\1|b\1'
 </pre></div>
 
-<p>This outputs an error message, because the second 
&lsquo;<samp>\1</samp>&rsquo;
+<p>This outputs an error message, because the second &lsquo;<samp 
class="samp">\1</samp>&rsquo;
 has nothing to refer back to, meaning it will never match anything.
 </p>
 </li><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
+Therefore, merely using the <code class="code">[:space:]</code> character 
class does not
 match newlines in the way you might expect.
 </p>
-<p>With the GNU <code>grep</code> option <samp>-z</samp> 
(<samp>--null-data</samp>), each
-input and output &ldquo;line&rdquo; is null-terminated; see <a 
href="Other-Options.html">Other Options</a>.  Thus,
+<p>With the GNU <code class="command">grep</code> option <samp 
class="option">-z</samp> (<samp class="option">--null-data</samp>), each
+input and output &ldquo;line&rdquo; is null-terminated; see <a class="pxref" 
href="Other-Options.html">Other Options</a>.  Thus,
 you can match newlines in the input, but typically if there is a match
 the entire input is output, so this usage is often combined with
-output-suppressing options like <samp>-q</samp>, e.g.:
+output-suppressing options like <samp class="option">-q</samp>, e.g.:
 </p>
 <div class="example">
-<pre class="example">printf 'foo\nbar\n' | grep -z -q 'foo[[:space:]]\+bar'
+<pre class="example-preformatted">printf 'foo\nbar\n' | grep -z -q 
'foo[[:space:]]\+bar'
 </pre></div>
 
 <p>If this does not suffice, you can transform the input
-before giving it to <code>grep</code>, or turn to <code>awk</code>,
-<code>sed</code>, <code>perl</code>, or many other utilities that are
+before giving it to <code class="command">grep</code>, or turn to <code 
class="command">awk</code>,
+<code class="command">sed</code>, <code class="command">perl</code>, or many 
other utilities that are
 designed to operate across lines.
 </p>
-</li><li> What do <code>grep</code>, <samp>-E</samp>, and <samp>-F</samp> 
stand for?
+</li><li> What do <code class="command">grep</code>, <samp 
class="option">-E</samp>, and <samp class="option">-F</samp> stand for?
 
-<p>The name <code>grep</code> comes from the way line editing was done on Unix.
+<p>The name <code class="command">grep</code> comes from the way line editing 
was done on Unix.
 For example,
-<code>ed</code> uses the following syntax
+<code class="command">ed</code> uses the following syntax
 to print a list of matching lines on the screen:
 </p>
 <div class="example">
-<pre class="example">global/regular expression/print
+<pre class="example-preformatted">global/regular expression/print
 g/re/p
 </pre></div>
 
-<p>The <samp>-E</samp> option stands for Extended <code>grep</code>.
-The <samp>-F</samp> option stands for Fixed <code>grep</code>;
+<p>The <samp class="option">-E</samp> option stands for Extended <code 
class="command">grep</code>.
+The <samp class="option">-F</samp> option stands for Fixed <code 
class="command">grep</code>;
 </p>
-</li><li> What happened to <code>egrep</code> and <code>fgrep</code>?
+</li><li> What happened to <code class="command">egrep</code> and <code 
class="command">fgrep</code>?
 
-<p>7th Edition Unix had commands <code>egrep</code> and <code>fgrep</code>
-that were the counterparts of the modern &lsquo;<samp>grep -E</samp>&rsquo; 
and &lsquo;<samp>grep -F</samp>&rsquo;.
-Although breaking up <code>grep</code> into three programs was perhaps
-useful on the small computers of the 1970s, <code>egrep</code> and
-<code>fgrep</code> were not standardized by POSIX and are no longer needed.
-In the current GNU implementation, <code>egrep</code> and <code>fgrep</code>
-issue a warning and then act like their modern counterparts;
+<p>7th Edition Unix had commands <code class="command">egrep</code> and <code 
class="command">fgrep</code>
+that were the counterparts of the modern &lsquo;<samp class="samp">grep 
-E</samp>&rsquo; and &lsquo;<samp class="samp">grep -F</samp>&rsquo;.
+Although breaking up <code class="command">grep</code> into three programs was 
perhaps
+useful on the small computers of the 1970s, <code class="command">egrep</code> 
and
+<code class="command">fgrep</code> were deemed obsolescent by POSIX in 1992,
+removed from POSIX in 2001, deprecated by GNU Grep 2.5.3 in 2007,
+and changed to issue obsolescence warnings by GNU Grep 3.8 in 2022;
 eventually, they are planned to be removed entirely.
 </p>
 <p>If you prefer the old names, you can use use your own substitutes,
-such as a shell script named <code>egrep</code> with the following
+such as a shell script named <code class="command">egrep</code> with the 
following
 contents:
 </p>
 <div class="example">
-<pre class="example">#!/bin/sh
+<pre class="example-preformatted">#!/bin/sh
 exec grep -E &quot;$@&quot;
 </pre></div>
 
@@ -373,7 +361,7 @@
 
 </div>
 <hr>
-<div class="header">
+<div class="nav-panel">
 <p>
 Next: <a href="Performance.html">Performance</a>, Previous: <a 
href="Regular-Expressions.html">Regular Expressions</a>, Up: <a 
href="index.html">grep</a> &nbsp; [<a href="index.html#SEC_Contents" 
title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" 
title="Index" rel="index">Index</a>]</p>
 </div>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]