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: Thu, 2 Jan 2020 18:18:46 -0500 (EST)

CVSROOT:        /webcvs/grep
Module name:    grep
Changes by:     Jim Meyering <meyering> 20/01/02 18:18:45

Index: html_node/Usage.html
===================================================================
RCS file: /webcvs/grep/grep/manual/html_node/Usage.html,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- html_node/Usage.html        30 Dec 2018 06:24:22 -0000      1.29
+++ html_node/Usage.html        2 Jan 2020 23:18:44 -0000       1.30
@@ -2,7 +2,7 @@
 <html>
 <!-- This manual is for grep, a pattern matching engine.
 
-Copyright (C) 1999-2002, 2005, 2008-2018 Free Software Foundation,
+Copyright (C) 1999-2002, 2005, 2008-2020 Free Software Foundation,
 Inc.
 
 Permission is granted to copy, distribute and/or modify this document
@@ -14,10 +14,10 @@
 <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-<title>Usage (GNU Grep 3.3)</title>
+<title>Usage (GNU Grep 3.4)</title>
 
-<meta name="description" content="Usage (GNU Grep 3.3)">
-<meta name="keywords" content="Usage (GNU Grep 3.3)">
+<meta name="description" content="Usage (GNU Grep 3.4)">
+<meta name="keywords" content="Usage (GNU Grep 3.4)">
 <meta name="resource-type" content="document">
 <meta name="distribution" content="global">
 <meta name="Generator" content="makeinfo">
@@ -83,7 +83,27 @@
 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
 it would not otherwise match.
-See <a href="Invoking.html#Invoking">Invoking</a>, for more details about
+</p>
+<p>Here is a more complex example session,
+showing the location and contents of any line
+containing &lsquo;<samp>f</samp>&rsquo; and ending in 
&lsquo;<samp>.c</samp>&rsquo;,
+within all files in the current directory whose names
+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
+treats any later arguments starting with &lsquo;<samp>-</samp>&rsquo; as file 
names not
+options, 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;.
+</p>
+<div class="example">
+<pre class="example">$ <kbd>grep -n -- 'f.*\.c$' *g*.h /dev/null</kbd>
+argmatch.h:1:/* definitions and prototypes for argmatch.c
+</pre></div>
+
+<p>The only line that contains a match is line 1 of <samp>argmatch.h</samp>.
+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">Invoking</a>, for more details about
 how to invoke <code>grep</code>.
 </p>
 <a name="index-using-grep_002c-Q_0026A"></a>
@@ -94,10 +114,10 @@
 <li> How can I list just the names of matching files?
 
 <div class="example">
-<pre class="example">grep -l 'main' *.c
+<pre class="example">grep -l 'main' test-*.c
 </pre></div>
 
-<p>lists the names of all C files in the current directory whose contents
+<p>lists names of &lsquo;<samp>test-*.c</samp>&rsquo; files in the current 
directory whose contents
 mention &lsquo;<samp>main</samp>&rsquo;.
 </p>
 </li><li> How do I search directories recursively?
@@ -109,42 +129,51 @@
 <p>searches for &lsquo;<samp>hello</samp>&rsquo; in all files
 under the <samp>/home/gigi</samp> directory.
 For more control over which files are searched,
-use <code>find</code>, <code>grep</code>, and <code>xargs</code>.
+use <code>find</code> and <code>grep</code>.
 For example, the following command searches only C files:
 </p>
 <div class="example">
-<pre class="example">find /home/gigi -name '*.c' -print0 | xargs -0r grep -H 
'hello'
+<pre class="example">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' *.c
+<pre class="example">grep -H 'hello' /home/gigi/*.c
 </pre></div>
 
-<p>which merely looks for &lsquo;<samp>hello</samp>&rsquo; in all files in the 
current
-directory whose names end in &lsquo;<samp>.c</samp>&rsquo;.
-The &lsquo;<samp>find ...</samp>&rsquo; command line above is more similar to 
the command:
+<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>
 <div class="example">
-<pre class="example">grep -rH --include='*.c' 'hello' /home/gigi
+<pre class="example">grep -r --include='*.c' 'hello' /home/gigi
 </pre></div>
 
-</li><li> What if a pattern has a leading &lsquo;<samp>-</samp>&rsquo;?
+</li><li> What if a pattern or file has a leading &lsquo;<samp>-</samp>&rsquo;?
 
 <div class="example">
-<pre class="example">grep -e '--cut here--' *
+<pre class="example">grep -- '--cut here--' *
 </pre></div>
 
 <p>searches for all lines matching &lsquo;<samp>--cut here--</samp>&rsquo;.
-Without <samp>-e</samp>,
+Without <samp>--</samp>,
 <code>grep</code> would attempt to parse &lsquo;<samp>--cut 
here--</samp>&rsquo; as a list of
-options.
+options, and there would be similar problems with any file names
+beginning with &lsquo;<samp>-</samp>&rsquo;.
 </p>
+<p>Alternatively, you can prevent misinterpretation of leading 
&lsquo;<samp>-</samp>&rsquo;
+by using <samp>-e</samp> for patterns and leading 
&lsquo;<samp>./</samp>&rsquo; for files:
+</p>
+<div class="example">
+<pre class="example">grep -e '--cut here--' ./*
+</pre></div>
+
 </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' *
+<pre class="example">grep -w 'hello' test*.log
 </pre></div>
 
 <p>searches only for instances of &lsquo;<samp>hello</samp>&rsquo; that are 
entire words;
@@ -154,7 +183,7 @@
 For example:
 </p>
 <div class="example">
-<pre class="example">grep 'hello\&gt;' *
+<pre class="example">grep 'hello\&gt;' test*.log
 </pre></div>
 
 <p>searches only for words ending in &lsquo;<samp>hello</samp>&rsquo;, so it 
matches the word
@@ -163,7 +192,7 @@
 </li><li> How do I output context around the matching lines?
 
 <div class="example">
-<pre class="example">grep -C 2 'hello' *
+<pre class="example">grep -C 2 'hello' test*.log
 </pre></div>
 
 <p>prints two lines of context around each matching line.
@@ -237,7 +266,7 @@
 <p>The <code>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;, &lsquo;<samp>.*</samp>&rsquo;, and many
+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
@@ -252,30 +281,6 @@
 <pre class="example">cat /etc/passwd | grep 'alain' - /etc/motd
 </pre></div>
 
-</li><li> <a name="index-palindromes"></a>
-How to express palindromes in a regular expression?
-
-<p>It can be done by using back-references;
-for example,
-a palindrome of 4 characters can be written with a BRE:
-</p>
-<div class="example">
-<pre class="example">grep -w -e '\(.\)\(.\).\2\1' file
-</pre></div>
-
-<p>It matches the word &ldquo;radar&rdquo; or &ldquo;civic.&rdquo;
-</p>
-<p>Guglielmo Bondioni proposed a single RE
-that finds all palindromes up to 19 characters long
-using 9&nbsp;subexpressions<!-- /@w --> and 9&nbsp;<span 
class="nolinebreak">back-references</span><!-- /@w -->:
-</p>
-<div class="smallexample">
-<pre class="smallexample">grep -E -e 
'^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\9\8\7\6\5\4\3\2\1$' file
-</pre></div>
-
-<p>Note this is done by using GNU ERE extensions;
-it might not be portable to other implementations of <code>grep</code>.
-</p>
 </li><li> Why is this back-reference failing?
 
 <div class="example">



reply via email to

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