Micah wrote:
File X contains a line with:
#else
Grepping:
case 1: 'grep -Ew -e "#else" X' returns "0":
#else
case 2: 'grep -E -e "\<#else\>" X' returns "1":
Although grep is operating as documented here, the documentation could be
better. I installed the attached patch to try to clear things up. Thanks for
reporting the problem.
>From cdd82ebbebe0113d0d252b385cc84e80d8ceac3a Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Tue, 25 Jul 2017 00:55:01 -0700
Subject: [PATCH] doc: distinguish -w from \<...\>
* doc/grep.texi (Matching Control):
Give example of why -w differs from \<...\> (Bug#27813).
---
doc/grep.texi | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/doc/grep.texi b/doc/grep.texi
index 64df316..24800c9 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -235,9 +235,17 @@ or preceded by a non-word constituent character.
Similarly,
it must be either at the end of the line
or followed by a non-word constituent character.
-Word-constituent characters are letters, digits, and the underscore.
+Word constituent characters are letters, digits, and the underscore.
This option has no effect if @option{-x} is also specified.
+Because the @option{-w} option can match a substring that does not
+begin and end with word constituents, it differs from surrounding a
+pattern with @samp{\<} and @samp{\>}. For example, although
+@samp{grep -w @@} matches a line containing only @samp{@@}, @samp{grep
+'\<@@\>'} cannot match any line because @samp{@@} is not a
+word constituent. @xref{The Backslash Character and Special
+Expressions}.
+
@item -x
@itemx --line-regexp
@opindex -x
--
2.7.4