Given the file with numbers from 1 to 100 (seq 1 100 > dataset.txt
),
and the pattern file with numbers from 1 to 20 (seq 1 20 > patterns.txt
),
I would like to to print all exact matches from the dataset file given the list of patterns.
Here is my command using BSD grep
:
$ \grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ \grep -w -F -f patterns.txt dataset.txt
1
2
3
4
5
6
7
8
9
but the output is missing the numbers from 10 to 20.
However all patterns are printed when running the same command in GNU grep
, e.g.
$ \ggrep --version
ggrep (GNU grep) 3.1
Packaged by Homebrew
$ \ggrep -w -F -f patterns.txt dataset.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
When tested with ripgrep
, all are returned as well.
Why is that? Is there any different approach to make them both return the same result?
-w
(which enables regexy bits) and-F
(which disables regexy bits). I'd either omit-w
or put the full exact regex into the pattern list file. – thrig Apr 26 '18 at 17:13-w
to-x
and try again. – Kusalananda Apr 26 '18 at 17:14-x
doesn't changes anything. – kenorb Apr 26 '18 at 17:39