I needed to view the ring buffer log on an older embedded Linux device. The device didn't have the new -T option for dmesg, didn't have bc or even a version of sed or bash that worked with the examples above. I ended creating a script using AWK to format the log dates based on runejuhl's sed script. Here is the script in case it's useful to someone.
#!/bin/sh
# print kernel ring buffer (dmesg log) with readable times if (dmsg -T not available)
# boot time in seconds
boottime=$(echo $(grep -m1 "btime" /proc/stat) | grep -Eo "[0-9]*$")
lines=$1
if [ -z $lines ]; then
lines=10
fi
#dislpay last x lines of kernel log using awk script instead of sed / bc
dmesg | tail -n $lines | awk 'match($0, /^\[ *([0-9]+\.[0-9]+)\]/) \
{ print strftime("[%a %d/%m/%Y %H:%M:%S]",sprintf("%.0f", ('$boottime' + substr($0, RSTART+1, RLENGTH-2)))) substr($0, RLENGTH+1) }'
This reads the time the system booted and stores it in a variable, then parses the log extracting the timestamp of each line adding it on to the boot time, formatting it to a date time string and writing it out with the rest of the line.
The boot time line (btime) is read from /proc/stat and the time extracted
boottime=$(echo $(grep -m1 "btime" /proc/stat) | grep -Eo "[0-9]*$")
the AWK match command is used to find the timestamp with a format of [ 0.0]
match($0, /^\[ *([0-9]+\.[0-9]+)\]/)
After a regex match the RSTART and RLENGTH variables hold the start and length of matched chars. The time stamp is extracted using a substring command, ignoring the [ ] substr($0, RSTART+1, RLENGTH-2)
The timestamp is then added onto the boottime value and rounded back to an integer using sprintf("%.0f", timestamp + boottime)
Finally the time is formatted to a readable value using strftime("[%a %d/%m/%Y %H:%M:%S]", logdate)
and the rest of the log line to printed using another substr command taking the rest of the line after the original timestamp substr($0, RLENGTH+1)