I am trying to match keywords listed in one file from text in another file. The keywords file is new line separated.
grep
returns different results based on the order of the keywords (not the input file).
Here is an example.
With this input
# input.txt
TRITONS, sea-deities; they sung the marriage chorus of ACHILLES.
Case 1
# terms.txt
ACHILLES
TRITONS
# grep returns just one match
grep -o -f terms.txt input.txt
ACHILLES
Case 2: I just changed the order of the keywords file
# terms.txt
TRITONS
ACHILLES
# grep returns both matches !
grep -o -f terms.txt input.txt
TRITONS
ACHILLES
Trying to understand the behavior.
I found this issue in grep (BSD grep) 2.5.1-FreeBSD
(this is the default version that ships on Mac High Sierra).
Fixed by using Gnu Grep ggrep (GNU grep) 3.4.
instead.
Installed via brew install grep
.
Note that this version of grep is now called ggrep
.