command变量可以根据自己需要修改成其他命令,比如:dmesg,其实dmesg查看时间戳可以使用dmesg -T。
#!/bin/sh
command=$(cat /var/log/dmesg.old | cut -d ']' -f1 --complement)
uptime_ts=$(cat /proc/uptime | awk '{ print $1}')
echo "${command}" | awk -v uptime_ts=$uptime_ts 'BEGIN {
now_ts = systime();
start_ts = now_ts - uptime_ts;
}
{
print strftime("[%Y/%m/%d %H:%M:%S]", start_ts + substr($1, 2, length($1) - 2)), $0
}'