I am writing a PHP command line script, and I’m wondering if any grep experts can help me to come up with a command to do the following:
For all files ending in .java in the current directory ($curDir), search within the file for any instance of $str, and return an indicator whether any instance has been found or not.
I’ve tried piecing together a grep command from various bits found on the internet but, having not really used grep before, its a bit difficult to piece together. I would appreciate any help.
Thanks!
This should do the trick:
Use
-lif you want it to just output the file names. Other grep options can be found here:http://unixhelp.ed.ac.uk/CGI/man-cgi?grep
Depending on what
$stris you may need to pass it through:escapeshellarg():http://www.php.net/manual/en/function.escapeshellarg.php