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/
GTS Joe
  • 199
  • 2
  • 10

2 Answers2

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/

David
  • 606
  • 4
  • 6
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.

WeSee
  • 486
  • 1
  • 4
  • 10