linux - Conversion from UTC to epoch shell script or awk -
okay i've got few test entries running quite time now, , start time logs
tue sep 29 09:21:39 utc 2015: info: tue sep 29 09:58:12 utc 2015: info: tue sep 29 09:58:58 utc 2015: info: tue sep 29 10:36:46 utc 2015: info: tue sep 29 11:10:26 utc 2015: info: tue sep 29 11:52:35 utc 2015: info: tue sep 29 12:19:37 utc 2015: info: tue sep 29 13:02:04 utc 2015: info: tue sep 29 13:55:41 utc 2015: info: tue sep 29 13:56:11 utc 2015: info: tue sep 29 13:56:17 utc 2015: info: tue sep 29 13:56:21 utc 2015: info:
i looking time different between subsequent entries, going give me time taken each test execute. there built-in awk commands can make use of convert these epoch can calculate difference quite easily?
what better approach? single line command great.
to convert each line equivalent unix timestamp
while ifs=: read dt1 dt2 dt3 _; date -d "$dt1:$dt2:$dt3" '+%s'; done < file.log 1443518499 1443520692 1443520738 1443523006 1443525026 1443527555 1443529177 1443531724 1443534941 1443534971 1443534977 1443534981
and print differential time in seconds between each line use:
while ifs=: read dt1 dt2 dt3 _; ts=$(date -d "$dt1:$dt2:$dt3" '+%s') [[ $pt ]] && echo $((ts-pt)) pt="$ts" done < file.log
output:
2193 46 2268 2020 2529 1622 2547 3217 30 6 4
Comments
Post a Comment