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
?
Asked
Active
Viewed 629 times
2

Zambezi
- 767
- 1
- 9
- 19
-
for searching source codes I would use ag (silver searcher) – Kent Aug 12 '14 at 14:14
-
possible duplicate of [Grep for literal strings](http://stackoverflow.com/questions/3242873/grep-for-literal-strings) – tripleee Aug 12 '14 at 14:17
2 Answers
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