diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-01-04 09:49:50 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-01-04 09:50:21 -0800 |
commit | 0dc6ab4153de00e530669e2b7d47b8c1968e1fa1 (patch) | |
tree | 02e7c22ef24eefa88c88369a4b0485ce1b2c0581 | |
parent | d1d7245219bc56e6a4f25c18d6f8f4b4b9bb42d6 (diff) | |
download | grep-0dc6ab4153de00e530669e2b7d47b8c1968e1fa1.tar.gz |
doc: document empty pattern better
* doc/grep.texi (Top, Fundamental Structure, Usage):
Explain how grep deals with the empty pattern.
Problem spotted by Bernhard Voelker in
<http://lists.gnu.org/archive/html/bug-grep/2012-01/msg00050.html>.
-rw-r--r-- | doc/grep.texi | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/doc/grep.texi b/doc/grep.texi index 78efb189..de73d7f0 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -50,7 +50,7 @@ Texts. A copy of the license is included in the section entitled @node Top @top grep -@command{grep} prints lines that match a pattern. +@command{grep} prints lines that contain a match for a pattern. This manual is for version @value{VERSION} of GNU Grep. @@ -1170,6 +1170,7 @@ The preceding item is matched at least @var{n} times, but not more than @end table +The empty regular expression matches the empty string. Two regular expressions may be concatenated; the resulting regular expression matches any string formed by concatenating two substrings @@ -1629,6 +1630,19 @@ grep 'paul' /etc/motd | grep 'franc,ois' finds all lines that contain both @samp{paul} and @samp{franc,ois}. @item +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 +other patterns cause @command{grep} to match every line. + +To match empty lines, use the pattern @samp{^$}. To match blank +lines, use the pattern @samp{^[[:blank:]]*$}. To match no lines at +all, use the command @samp{grep -f /dev/null}. + +@item How can I search in both standard input and in files? Use the special file name @samp{-}: |