我有一个包含两列的 csv 日志文件,每列都有请求(第一列)和响应(第二列)的时间戳。
以下是一些示例数据:
2013-07-11 08:39:08.748,2013-07-11 08:39:08.748
2013-07-11 08:39:08.826,2013-07-11 08:39:08.826
2013-07-11 08:39:08.860,2013-07-11 08:39:08.860
2013-07-11 08:39:08.919,2013-07-11 08:39:08.919
2013-07-11 08:39:08.941,2013-07-11 08:39:08.941
2013-07-11 08:39:09.390,2013-07-11 08:39:09.390
2013-07-11 08:39:09.594,2013-07-11 08:39:09.594
2013-07-11 08:39:09.619,2013-07-11 08:39:09.619
2013-07-11 08:39:09.787,2013-07-11 08:39:09.787
2013-07-11 08:39:10.006,2013-07-11 08:39:10.006
2013-07-11 08:39:10.017,2013-07-11 08:39:10.017
2013-07-11 08:39:10.088,2013-07-11 08:39:10.088
2013-07-11 08:39:10.214,2013-07-11 08:39:10.214
我想计算完整文件的两列(响应 - 请求)差异的平均值。该文件一天可以包含数百万个条目。
我正在寻找一种使用 shell 脚本的方法。请帮忙。
谢谢 Fedorqui,我试过你的脚本:
while read line;
do
d1=$(echo $line | cut -d, -f1);
d2=$(echo $line | cut -d, -f2);
ds1=$(date -d"$d1" "+%s");
ds2=$(date -d"$d2" "+%s");
echo "$ds2 - $ds1 = $(( $ds1 - $ds2))";
done < requestResponse.csv
它给了我以下结果:
1373543260 - 1373543260 = 0
1373543260 - 1373543260 = 0
1373543260 - 1373543260 = 0
1373543260 - 1373543260 = 0
1373543260 - 1373543260 = 0
1373543260 - 1373543260 = 0
1373543260 - 1373543260 = 0
1373543261 - 1373543261 = 0
1373543262 - 1373543262 = 0
1373543262 - 1373543262 = 0
我需要以毫秒为单位的差异。