14

Running on MacOSX 10.13.3 using the default terminal. When I try to use the grep command, I receive this as the output. No matter what. I've changed directories, options, and even grep alone returns the same thing. It returns:

grep: conflicting matchers specified

Recently, I was installing some new command line tools with Homebrew, and believe I ran brew install grep in the process to get the the official linux version on my computer. That's the only change I can think of that could have led to this.

Here's the trace. As you can see the grep command ran successfully, but the output was the error message instead of the results:

Command

grep -l 'this' *.txt

Trace

+ grep -GFh -l this ga_users.txt montecitovt_apache_logs-2018-02-09_21-58-40.txt tag_manager_more_than_one_ga_account.txt urls_in_sitemap.txt
grep: conflicting matchers specified
++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=

...

[REDACTED]
Josh Bradley
  • 1,854
  • 1
  • 15
  • 31

4 Answers4

9

As you can see in the first line of the trace, the first argument grep receives is -GFh.

-G specifies regular expressions, while -F specifies fixed strings. These are of course incompatible.

It's unclear why grep would execute as grep -GFh ...., but the most likely possibility (as suggested in a comment) is probably an alias. You can verify this using alias grep, which will print whether or not grep is aliased, or type grep, which is more general (e.g. if grep is defined as a function, it will tell you that).

Kyle Strand
  • 15,941
  • 8
  • 72
  • 167
  • 1
    It's important to understand that unlike many other command line tools, GNU `grep` doesn't interpret conflicting parser modes using the "last option wins" method. As a result, you get problems if you have any mode characters in e.g. alias. For example `git grep -FP ...` works just fine and the actually used mode is `-P` in that case. – Mikko Rantalainen Jan 29 '21 at 09:30
3

I had grep set as an alias in my ~./bashrc. I was made of aware of this by smart people in the comments who noticed that grep was being called with options already set. I removed the alias for grep and everything is working great.

Josh Bradley
  • 1,854
  • 1
  • 15
  • 31
3

I had aliases that were 'stacking':

alias grep='grep --color=auto -i --perl-regexp'
alias fgrep='grep -Fi --color=auto'

Changing the 2nd one to \grep (leading backslash) makes them not stack.

mpen
  • 272,448
  • 266
  • 850
  • 1,236
1

If you get this error with egrep or fgrep change it from that variant to the base grep command. Per the grep man page:

egrep is the same as grep -E.
fgrep is the same as grep -F.
Direct invocation as either egrep or fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified.

So, as Kyle Strand mentions in his answer, adding a matcher flag to egrep or fgrep can easily create that conflict.

Randall
  • 2,859
  • 1
  • 21
  • 24