shell编程 shell中如何计算两个时间的时间差?

shell中如何计算两个时间的时间差?A:参考代码如下:start=`date%s-D“2011-11-28 15:55:37”end=`date%s-D“2011-11-28 15:55:52”ec

shell中如何计算两个时间的时间差?

A:参考代码如下:

start=`date%s-D“2011-11-28 15:55:37”

end=`date%s-D“2011-11-28 15:55:52”

echo$((($end-$start))

此前提基于开始和结束时间字符串。

如果日志文件输出格式如上所述,则还有另一种方法:

cat log file | awk“/^000/{

start=$2“”$3

end=$4“”$5

STM=mktime(gensub(/[:]/,”,”g“,start))

ETM=mktime(gensub(/[:]/,”,”g“,end))

print$1“-”ETM STM

}