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
}