Created
February 25, 2013 15:03
-
-
Save compor/5030393 to your computer and use it in GitHub Desktop.
elapsed time between two log records
This file contains hidden or 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
| #!/bin/bash | |
| # | |
| # parses the time (in seconds) that elapsed between 2 consecutive entries | |
| # each matching to pattern1 and pattern2. | |
| # date format : [DDD] [MMM] [dd] [hh]:[mm]:[ss] [YYYY] | |
| # example : Tue May 12 06:49:44 2009 | |
| # | |
| # substitute the patterns at will | |
| # | |
| # limitation : it works for entries having the same year | |
| # | |
| # example | |
| # Tue May 12 06:49:41 2009 - pattern1 | |
| # Tue May 12 06:49:44 2009 - pattern2 | |
| # | |
| # it should output : | |
| # 3 | |
| # | |
| awk ' | |
| BEGIN{ | |
| m["Jan"]="01"; | |
| m["Feb"]="02"; | |
| m["Mar"]="03"; | |
| m["Apr"]="04"; | |
| m["May"]="05"; | |
| m["Jun"]="06"; | |
| m["Jul"]="07"; | |
| m["Aug"]="08"; | |
| m["Sep"]="09"; | |
| m["Oct"]="10"; | |
| m["Nov"]="11"; | |
| m["Dec"]="12"; | |
| d["Sun"]="01"; | |
| d["Mon"]="02"; | |
| d["Tue"]="03"; | |
| d["Wed"]="04"; | |
| d["Thu"]="05"; | |
| d["Fri"]="06"; | |
| d["Sat"]="07"; | |
| s=0; # start timestamp | |
| e=0; # end timestamp | |
| } | |
| /pattern1/ { dt1=$0; gsub(":"," ",$4); | |
| spec1=sprintf("%s %s %s %s",$5,d[$1],m[$2],$4); | |
| s=mktime(spec1); } | |
| /pattern2/ { | |
| dt2=$0; gsub(":"," ",$4); | |
| spec2=sprintf("%s %s %s %s",$5,d[$1],m[$2],$4); | |
| e=mktime(spec2); print e-s; e=s=0; }' < $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment