Created
December 7, 2012 21:04
-
-
Save anirupdutta/4236528 to your computer and use it in GitHub Desktop.
Parse Iperf CSV Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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