如何汇总日期格式的开始时间和毫秒的运行时间以在UNIX脚本中找到结束时间?

我有一个文件,该文件的开始时间为一列,格式如下所示。

Multiple valid **development certificates** available (your choice will be saved):
  1) iPhone Developer: xxxx@xxxxxx (G3xxxxx9X)
  2) iPhone Developer: xxxx xxxx (4UxxxxC8)
  a) Abort                                                                                      

我还有一个文件,其中包含以毫秒为单位执行的作业的运行时间。

2019-10-30T08:04:30Z
2019-10-30T08:04:25Z
2019-10-30T08:04:30Z

。 。

如何在这些文件的两列中添加相应的行,并在单独的文件中产生结束时间?

beachboyll 回答:如何汇总日期格式的开始时间和毫秒的运行时间以在UNIX脚本中找到结束时间?

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(输入文件)
  • execution_time.txt(输入文件)
  • end_time.txt(输出文件)
本文链接:https://www.f2er.com/3154175.html

大家都在问