我有一个这种格式的日志文件:
10:33:56 some event occurs
10:33:57 another event occurs
10:33:59 another one occurs
我想制作相对于开始时间的时间:
00:00:00 some event occurs
00:00:01 another event occurs
00:00:03 another one occurs
使用bash脚本。这将允许我比较更好的不同执行延迟。
答案 0 :(得分:-2)
可以制作此脚本rebase_time.sh
:
adddate() {
while IFS= read -r line; do
log_file_hours=`echo $line | awk 'BEGIN{FS="[ [/:]+"}; {print $1}'`
log_file_minutes=`echo $line | awk 'BEGIN{FS="[ [/:]+"}; {print $2}'`
log_file_seconds=`echo $line | awk 'BEGIN{FS="[ [/:]+"}; {print $3}'`
log_date="$log_file_hours:$log_file_minutes:$log_file_seconds"
if [[ -z "$first_date" ]]; then
first_date=$log_date
fi
StartDate=$(date -u -d "$first_date" +"%s")
FinalDate=$(date -u -d "$log_date" +"%s")
diff=$(date -u -d "0 $FinalDate sec - $StartDate sec" +"%H:%M:%S")
echo $diff ${line#$log_date}
done
}
cat "$1" | adddate
并以这种方式称呼它:
./rebase_time events.log