Skip to content

Instantly share code, notes, and snippets.

@jwestbrook
Created October 11, 2016 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwestbrook/d46790700642cbc258b1a7d6514f3247 to your computer and use it in GitHub Desktop.
Save jwestbrook/d46790700642cbc258b1a7d6514f3247 to your computer and use it in GitHub Desktop.
#!/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