[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: empty pattern: info clarification?
From: |
Paul Eggert |
Subject: |
Re: empty pattern: info clarification? |
Date: |
Tue, 03 Jan 2012 10:15:39 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0 |
On 01/03/12 03:18, Voelker, Bernhard wrote:
> +The empty expression matches any string
Thanks for reporting the problem. The fix is not quite right,
though, as strictly speaking the empty expression matches
only the empty string.
Here's a proposed patch that tries to address the problem better:
>From cb0745b1fec8f050567ab6a2dc5b68d2c55827a2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Tue, 3 Jan 2012 10:09:51 -0800
Subject: [PATCH] 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>.
---
doc/grep.texi | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/doc/grep.texi b/doc/grep.texi
index 537237f..25019b4 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
address@hidden prints lines that match a pattern.
address@hidden prints lines that contain a match for a pattern.
This manual is for version @value{VERSION} of GNU Grep.
@@ -1162,6 +1162,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
@@ -1621,6 +1622,18 @@ 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 specify a pattern that matches none of the input lines, use
address@hidden -f /dev/null}.
+
address@hidden
How can I search in both standard input and in files?
Use the special file name @samp{-}:
--
1.7.6.4