Reputation: 653
I have the following PHP code snippet to run awk. It returns the right record entries. However, I cannot extract the individual fields from each of the record using PHP? I tried preg_split with " " delimiter but, it did not output anything. Thanks.
$cmd = "/usr/bin/awk '{if($1 >= \"$s_period\" && $1 <= \"$e_period\"){print $1,$2}}' File_Path";
exec($cmd,$output);
foreach ($output as $result)
{
$temp = preg_split(" ",$result);
echo "$temp[0]\t$temp[1]<br />"; //no output
}
The input file is in format: 2013-04-03(date) 67788.7(val1) 4555(val2) 5555(val3) $output contains record as "2013-04-03 67788.7". That is, date followed by stats
Upvotes: 1
Views: 373
Reputation: 3799
$output contains record as "2013-07-15 6361.97". That is, date followed by stats
To split your $output
string into an array:
$temp = explode(" ", $output);
To output the individual bits:
echo "{$temp[0]}\t{$temp[1]}<br />";
Upvotes: 1