bash - dmesg convert timestamps to human format -


i have following sample of dmesg:

 throttled log output. 57458] bar 3: test 2 on bar 8 available [   19.696163] bar 1403: test on bar 1405 available [   19.696167] foo: [   19.696168] bar 3: test 5 on bar 1405 available [   19.696178] foo: [   19.696179] bar 1403: test 5 on bar 1405 available [   20.928730] foo: [   20.928733] bar 1403: test on bar 1408 available [   20.928742] foo: [   20.928745] bar 3: test on bar 1408 available [   24.878861] foo: [   25.878861] foo: [   25.878863] bar 1403: bar 802 present 

i convert all timestamps in line human format ("%d/%m/%y %h:%m:%s")

notes: system not have dmesg -t nor has perl installed. prefer solution w/ sed or awk, python option.

i've found few solutions problem, none quite answers need. nor know how modify needs.

awk -f"]" '{"cat /proc/uptime | cut -d \" \" -f 1" | getline st;a=substr( $1,2, length($1) - 1);print strftime("%d/%m/%y %h:%m:%s",systime()-st+a)" "$0}' 

or

sed -n 's/\]//;s/\[//;s/\([^.]\)\.\([^ ]*\)\(.*\)/\1\n\3/p' |  while read first;    read second;    first=`date +"%d/%m/%y %h:%m:%s" --date="@$(($seconds - $base + $first))"`;   printf "[%s] %s\n" "$first" "$second";  done 

there's python script in here. outputs errors have 0 understanding in.

thanks!

this bit touch-and-go, should @ least give work with:

awk '   {     # tail part of line still requires processing     tail = $0;                                     # read uptime /proc/uptime , use calculate system     # start time     "cat /proc/uptime | cut -d \" \" -f 1" | getline st;     starttime = systime() - st;      # while find matches     while((start = match(tail, /\[[^[]*\]/)) != 0) {       # pick timestamp match       s = substr(tail, start + 1, rlength - 2);        # shorten tail accordingly       tail = substr(tail, start + rlength);        # format time our preference       t = strftime("%d/%m/%y %h:%m:%s", starttime + s);        # substitute original line. [] replaced ||       # match not re-replaced in next iteration.       sub(/\[[^[]*\]/, "|" t "|", $0);     }      # when matches have been replaced, print line.     print $0   }' foo.txt 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -