如何将日期格式的开始时间和以毫秒为单位的运行时间相加,以在unix脚本中找到结束时间?
我有一个文件,其中有一列的起始时间如下所示如何将日期格式的开始时间和以毫秒为单位的运行时间相加,以在unix脚本中找到结束时间?,unix,timestamp,add,milliseconds,Unix,Timestamp,Add,Milliseconds,我有一个文件,其中有一列的起始时间如下所示 2019-10-30T08:04:30Z 2019-10-30T08:04:25Z 2019-10-30T08:04:30Z 此外,我还有一个文件,其中包含以毫秒格式执行的作业的运行时间 2647ms 360ms 10440ms 。 . 如何在这些文件的两列中添加相应的行,并在单独的文件中生成结束时间 paste start_time.txt execution_time.txt | while IFS="$(printf '\t')" rea
2019-10-30T08:04:30Z
2019-10-30T08:04:25Z
2019-10-30T08:04:30Z
此外,我还有一个文件,其中包含以毫秒格式执行的作业的运行时间
2647ms
360ms
10440ms
。
.
如何在这些文件的两列中添加相应的行,并在单独的文件中生成结束时间
paste start_time.txt execution_time.txt | while IFS="$(printf '\t')" read -r f1 f2
do
# convert execution_time in seconds from ms
execution_time_ms="$(echo $f2 | cut -d'm' -f1)"
execution_time_ms="$(echo $execution_time_ms | cut -d's' -f1)"
execution_time_s=$(awk "BEGIN {printf \"%.10f\",$execution_time_ms/1000}")
# create dateformat string to add seconds
date_format=$f1
date_format+=" +$execution_time_s"
date_format+="seconds"
# create end date using dateformat string
end_time=`date --date="$date_format" +'%Y-%m-%d %H:%M:%S'`
end_time="${end_time/ /T}"
end_time+='Z'
# append end time
echo $end_time >> end_time.txt
done
这是一个解决您的问题的脚本。
根据你提到的,我已经使用了3个文件
- start_time.txt(输入文件)
- 执行时间.txt(输入文件)
- end_time.txt(输出文件)