I had this problem with grep where I needed to find characters such as ' or [ and it wouldn't find them, no matter if I had backslashes or not before, and no matter if I used ' to enclose the search string or not - which is what I've always seen used in all the documentation I could find.
So, what's the trick here? Just use " " to enclose your search string, and backslashes before every regular expression special character, because grep assumes that the search string is going to be a regexp.
Example: let's assume that we have a bunch of php files under different subdirectories in /www/ and we want to find all the ones containing a certain variable, let's say $_SERVER['SERVER_NAME']
The correct grep command to find it would be:
grep -r "\$_SERVER\['SERVER_NAME']" /www/*
If you want to learn more about regexp, http://www.regular-expressions.info/ is a great place to start.
Hope this helped, for any question - head to the forums.
Credits for this go to: Inc0 and Prose.



