linux - Command to find the time difference -


i have log, dumped 1 or more process simultaneously. sometimes, because of cpu on load , context switching, logging file delayed. want find time difference between each line , print before each line?

log example:

07/18 16:20:29886564 pid= 2998,tid= 3036,  xxxxx.c:  335:xxxxx:### xxxxxxxxxxxxxxxxxx ###  07/18 16:20:29886642 pid= 2998,tid= 3036,  xxxxx.c:  484:xxxxx:### yyyyyyyyyyyyyyy()  07/18 16:20:29886880 pid= 2998,tid= 3036,  xxxxx.c:  488:xxxxx:>>>yyyyyyyyyyyyy()  07/18 16:20:29887002 pid= 2998,tid= 3036,  xxxxx.c:  494:xxxxx:>>>ok: zzzzzzzzzzzzzzz() 

i suppose possible 'awk'. but, pretty bad @ linux commands. please this?

you can try following awk command. have commented can understand how works:

awk '{   # split time field   split($2,arr,":");     # convert hours , mins seconds , compute total   curr=arr[3]+arr[2]*60+arr[1]*60*60;    # set previous value first line   if(prev == 0) prev=curr;    # print out difference between current , previous totals   print curr-prev,$0;    # set previous current   prev=curr; }' file 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -