Sample Header Ad - 728x90

Inverse grep does not find all matching lines

4 votes
1 answer
868 views
**EDIT:** I am making this too complicated. It's not about inverse grep. I get the same results using just grep -x -f stop.txt < in.txt. If who comes before whose in the stop word file, the result is just who. When the order is reversed in the stop word file, both lines in in.txt are found. I have the feeling that I fundamentally do not get grep. *** I cannot get inverse grep to work like I expect in order to remove lines containing a stop word from a file. The order in which the stop words are given affects the result. Suppose I have two files. An input file in.txt:
who
whose
And a file with a list of stop words stop.txt:
who
whose
If I "filter" in.txt with an inverse grep search on the stop words in `stop.txt`, I get:
$ grep -vx -f stop.txt < in.txt
whose
$
Only if I change stop.txt to
whose
who
do I get:
$ grep -vx -f stop.txt < in.txt
$
I do not understand why the order of words in the file with stop words is of importance.
Asked by Till A. Heilmann (141 rep)
Sep 9, 2022, 12:27 PM
Last activity: Sep 9, 2022, 09:25 PM