How to print stuff in a loop to console, so that UNIX grep can interact with it ? I made a console php tool for parsing some data. I am in need of printing some data to console.
public function printAlerts()
{
$alertLinks = $this->parser->alertLinks($this->mc->listAlerts());
$idSize = $alertLinks['sizeArray']['id'];
$dateSize = $alertLinks['sizeArray']['date'];
$nameSize = $alertLinks['sizeArray']['name'];
$margin = 5;
foreach ($alertLinks['alertArray'] as $alert)
{
$this->printColumn($alert['id'], $idSize, $margin);
$this->printColumn($alert['date'], $dateSize, $margin);
$this->printColumn($alert['name'], $nameSize, $margin);
echo "
";
}
}
private function printColumn($data, $space = 0, $margin = 0)
{
echo $data;
$len = ($space - strlen($data)) + $margin;
for ($i = 0; $i < $len; $i++)
{
echo ' ';
}
return;
}
I would like to interact with this printed data with Unix grep command. For example:
php script.php -list | grep stuff
Using this code all data gets printed in the console, but grep can not filter it, why? how to make grep filter the text ?