Skip to content

Instantly share code, notes, and snippets.

@anirupdutta
Created December 7, 2012 21:04
Show Gist options
  • Save anirupdutta/4236528 to your computer and use it in GitHub Desktop.
Save anirupdutta/4236528 to your computer and use it in GitHub Desktop.
Parse Iperf CSV Data
<?php
function convert_bytes($bytes)
{
if($bytes >= 1048576)
{
$megabytes = round(($bytes/(1000*1000)),2);
return $megabytes;
}
else
{
$kilobytes = round(($bytes/1000),2);
return $kilobytes;
}
}
if(array_key_exists(2,$argv))
{
$filename = $argv[1];
}
else
{
echo "Usage \"php parse.php inputfilename outputfilename\"\n";
}
if(isset($filename))
{
if (file_exists($filename))
{
$file_contents = file_get_contents($filename);
$chunks = explode(",", $file_contents);
$count = 16;
echo "\n";
$output = '';
while($count < sizeof($chunks))
{
$output = $output.convert_bytes($chunks[$count]).",";
$count += 21;
}
file_put_contents($argv[2],$output);
}
else
{
echo "The file $filename does not exist\n";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment