0

I'm trying to use grep to find a specific line of PHP code I know for certain is present in several files, but all I get back is an empty result. Please advise on how I need to modify my grep query:

sudo grep -ilr 'if (isset($_COOKIE["id"])) @$_COOKIE["user"]($_COOKIE["id"]);' /path/to/dir/
3

. * ^ $ [ and ] have special meaning in regular expressions and need to be backslash escaped.

sudo grep -ilr 'if (isset(\$_COOKIE\["id"\])) @\$_COOKIE\["user"\](\$_COOKIE\["id"\]);' /path/to/dir/

1

I'd use two greps for making search easier:

sudo grep -Inri 't(\$_C' |grep '"id' /path/to/dir

The first grep searches for t($_C and the second for "id so you have a good chance to find your file.

And you avoid to blow up your search pattern with whitespaces and similar characters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.