I need to search for a PHP variable $someVar
. 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.
grep is one of the most useful and powerful commands in Linux for text processing. grep searches one or more input files for lines that match a regular expression and writes each matching line to standard output.
Exclude Words and Patterns To display only the lines that do not match a search pattern, use the -v ( or --invert-match ) option. The -w option tells grep to return only those lines where the specified string is a whole word (enclosed by non-word characters). By default, grep is case-sensitive.
Grep is an implementation of POSIX regular expressions. There are two types of posix regular expressions -- basic regular expressions and extended regular expressions. In grep, generally you use the -E option to allow extended regular expressions.
Use fgrep
(deprecated), grep -F
or grep --fixed-strings
, to make it treat the pattern as a list of fixed strings, instead of a regex.
For reference, the documentation mentions (excerpts):
-F
--fixed-strings
Interpret the pattern as a list of fixed strings (instead of regular expressions), separated by newlines, any of which is to be matched. (-F is specified by POSIX.)
fgrep
is the same asgrep -F
. Direct invocation as fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified.
For the complete reference, check: https://www.gnu.org/savannah-checkouts/gnu/grep/manual/grep.html
grep -F
is a standard way to tell grep
to interpret argument as a fixed string, not a pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With