dotancohen dotancohen - 1 year ago 102
Linux Question

Grep not as a regular expression

I need to search for a PHP variable

. However, Grep thinks that I am trying to run a regex and is complaining:

$ grep -ir "Something Here" * | grep $someVar
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
$ grep -ir "Something Here" * | grep "$someVar"
<<Here it returns all rows with "someVar", not only those with "$someVar">>

I don't see an option for telling grep not to interpret the string as a regex, but to include the
as just another string character.

Answer Source

Escape the $ by putting a \ in front of it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download