I can't figure out how to get grep to return all lines found in a file. It counts the correct number but only prints the last match.
$found = array();
$term = escapeshellarg(self::$term);
foreach(self::$files as $file)
{
if($count = exec("grep -i -c ".$term." ".$file))
{
$lines = exec("grep -i -n ".$term." ".$file);
$found[] = array('count'=>$count,'lines'=>$lines,'file'=>str_replace(self::$dir, '', $file));
}
}
self::$files = $found;
Let's say self::$term = 'console.log'
. It finds three matches in one particular file, which is correct (the term appears on lines 16, 21, and 31 of a test file), but $lines
only prints: 31: console.log(response);
.
What am I missing?