开发者

Shell Script needed - I have to collect time stamps from appserver logs

I have to col开发者_如何学Golect time stamps from appserver logs and store it in an output file. Finally have to find the difference between each timestamps and print it. For example: If i have 10 timestapms collected and kept in a file. Have to find difference between 10th and 9th. 9th and 8th...........2nd and 1st timestamp. can anyone help me in writing shell scripting for this?


To extract the timestamps and convert to an epoch time:

perl -MTime::Local -ne ' 
    ($ts, $y, $m, $d, $H, $M, $S, $frac) = 
        /((\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)\.(\d+))/;
    $time = timelocal($S, $M, $H, $d, $m-1, $y-1900) + "0.$frac";
    print $ts, ",", $time, "\n";
' log.file > output.file

Given your input, this would output

2011-04-12 06:49:02.874,1302605342.874

To find the differences, you can now just do arithmetic on the time value in the last column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜