I am trying to use grep -w to match a word, but it seems that grep ignores
the -w switch and returns all occurencies.
$ cat file1
one two three
$ grep -w 'two' file1 #or grep -Ew 'two'
Result: all four lines of file1 are returned.
According to man grep:
Select only those lines containing matches that form whole
words. The test is that the matching substring must either be at
the beginning of the line, 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
digits, and the underscore. This option has no effect if -x is also
Since dash '-' does not belong to word-constituent characters i was
expecting only first line to be matched : one two three
Just for the record , even options \<two\>, or \btwo\b will also return all
Easy workaround for the job would be to use
grep ' two ' or grep -E '\stwo\s'
But this bug report is focused on the failure of -w flag