-
-
Save jwestbrook/d46790700642cbc258b1a7d6514f3247 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/php | |
<?php | |
$fh = fopen($_SERVER['argv'][1],"r"); | |
function compare($a , $b) | |
{ | |
if($a['msec'] < $b['msec']) | |
{ | |
return -1; | |
} | |
elseif($a['msec'] > $b['msec']) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
$lines_same_second = array(); | |
$current_second = null; | |
while($line = fgets($fh)) | |
{ | |
list($dts,$data) = explode(" ",$line); | |
$dts_unix = strtotime($dts); | |
preg_match("/[0-9]{2}:[0-9]{2}:[0-9]{2}\.([0-9]+)/",$dts,$mseconds); | |
if($dts_unix == $current_second) | |
{ | |
$lines_same_second[] = array('msec' => $mseconds[1], "line" => $line); | |
} | |
else | |
{ | |
usort($lines_same_second,"compare"); | |
foreach($lines_same_second as $l) | |
{ | |
file_put_contents("fixed.txt",$l['line'],FILE_APPEND); | |
} | |
$lines_same_second = array(); | |
$lines_same_second[] = array('msec' => $mseconds[1], "line" => $line); | |
$current_second = $dts_unix; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment