2

I have this phantom block of code that is messing up my program, but I can simply NOT find where it is in my project. I know exactly (to the whitespace) what the code would be, but since it is code it has a lot of spaces, periods, brackets, ect. It would be a huge pain to type out a regular expression for the whole thing. Is there a way I could just search for an exact match to a string using grep -r?

Zambezi
  • 767
  • 1
  • 9
  • 19

2 Answers2

3

fgrep does this (or grep -F). Don't forget to quote the pattern to prevent the shell from interpreting it:

$ echo 'a' | grep '[abc]'
a
$ echo 'a' | fgrep '[abc]'
$ echo '[abc]' | fgrep '[abc]'
[abc]
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
1

If it is a multiline pattern, pcregrep -F can be useful (-F for with fixed string).

martin
  • 3,149
  • 1
  • 24
  • 35