Bash 从相对于开始时间的日志文件中创建时间
我有一个以下格式的日志文件:Bash 从相对于开始时间的日志文件中创建时间,bash,logging,Bash,Logging,我有一个以下格式的日志文件: 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脚本。这将允许我比较更好的不同执行延迟。可以使此脚本重新设置时间。sh: addd
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脚本。这将允许我比较更好的不同执行延迟。可以使此脚本
重新设置时间。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
这些是24小时制的吗?如果时间到了第二天会发生什么?那将是另一个问题。这类日志文件存在问题。例如:Jenkins以这种格式显示日志。但是你可以发布你自己的解决方案,或者告诉我如何解决这个问题。我问的是这些日志,你在同一分钟内只显示了3次不同的时间,从来没有提到它是什么类型的日志。。。