[Top][All Lists]

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

grep branch, master, updated. v3.3-58-gfdee61d

From: Paul Eggert
Subject: grep branch, master, updated. v3.3-58-gfdee61d
Date: Mon, 30 Dec 2019 04:57:19 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  fdee61d847ed6c78901bd5620f1d421c51468181 (commit)
      from  71635837d14c842ceb8a0c096b52656936ac4965 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------

commit fdee61d847ed6c78901bd5620f1d421c51468181
Author: Paul Eggert <address@hidden>
Date:   Mon Dec 30 01:56:36 2019 -0800

    doc: robustify some examples
    Prompted by suggestions by Stephane Chazelas (Bug#38792#20).
    * doc/grep.texi (Usage): Make examples more robust.

diff --git a/doc/grep.texi b/doc/grep.texi
index 13b8df0..aceaf33 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -1615,11 +1615,11 @@ Here are some common questions and answers about 
@command{grep} usage.
 How can I list just the names of matching files?
-grep -l 'main' *.c
+grep -l 'main' test-*.c
 @end example
-lists the names of all C files in the current directory whose contents
+lists names of @samp{test-*.c} files in the current directory whose contents
 mention @samp{main}.
@@ -1633,45 +1633,54 @@ grep -r 'hello' /home/gigi
 searches for @samp{hello} in all files
 under the @file{/home/gigi} directory.
 For more control over which files are searched,
-use @command{find}, @command{grep}, and @command{xargs}.
+use @command{find} and @command{grep}.
 For example, the following command searches only C files:
-find /home/gigi -name '*.c' -print0 | xargs -0r grep -H 'hello'
+find /home/gigi -name '*.c' ! -type d \
+  -exec grep -H 'hello' '@{@}' +
 @end example
 This differs from the command:
-grep -H 'hello' *.c
+grep -H 'hello' /home/gigi/*.c
 @end example
-which merely looks for @samp{hello} in all files in the current
-directory whose names end in @samp{.c}.
-The @samp{find ...} command line above is more similar to the command:
+which merely looks for @samp{hello} in non-hidden C files in
+@file{/home/gigi} whose names end in @samp{.c}.
+The @command{find} command line above is more similar to the command:
-grep -rH --include='*.c' 'hello' /home/gigi
+grep -r --include='*.c' 'hello' /home/gigi
 @end example
-What if a pattern has a leading @samp{-}?
+What if a pattern or file has a leading @samp{-}?
-grep -e '--cut here--' *
+grep -- '--cut here--' *
 @end example
 searches for all lines matching @samp{--cut here--}.
-Without @option{-e},
+Without @option{--},
 @command{grep} would attempt to parse @samp{--cut here--} as a list of
+options, and there would be similar problems with any file names
+beginning with @samp{-}.
+Alternatively, you can prevent misinterpretation of leading @samp{-}
+by using @option{-e} for patterns and leading @samp{./} for files:
+grep -e '--cut here--' ./*
+@end example
 Suppose I want to search for a whole word, not a part of a word?
-grep -w 'hello' *
+grep -w 'hello' test*.log
 @end example
@@ -1682,7 +1691,7 @@ For more control, use @samp{\<} and
 For example:
-grep 'hello\>' *
+grep 'hello\>' test*.log
 @end example
@@ -1693,7 +1702,7 @@ searches only for words ending in @samp{hello}, so it 
matches the word
 How do I output context around the matching lines?
-grep -C 2 'hello' *
+grep -C 2 'hello' test*.log
 @end example
@@ -1775,7 +1784,7 @@ Why does the empty pattern match every input line?
 The @command{grep} command searches for lines that contain strings
 that match a pattern.  Every line contains the empty string, so an
 empty pattern causes @command{grep} to find a match on each line.  It
-is not the only such pattern: @samp{^}, @samp{$}, @samp{.*}, and many
+is not the only such pattern: @samp{^}, @samp{$}, and many
 other patterns cause @command{grep} to match every line.
 To match empty lines, use the pattern @samp{^$}.  To match blank


Summary of changes:
 doc/grep.texi | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)


reply via email to

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