[英]How to get Difference in time data kept in two different files in Unix?
I Have Two files each with some 200K Timestamps in a single column. 我在同一列中有两个文件,每个文件带有大约200K时间戳。 I want to find the difference between each rows(mapped one to one) in seconds. 我想在几秒钟内找到每一行之间的差异(一对一映射)。
For example: 例如:
One file has 2013-06-04 11:21:28
and Second file 2013-06-04 11:21:55
in the same row, so I want to get the output as 27. That is 27 seconds. 一个文件在同一行中具有2013-06-04 11:21:28
2013-06-04 11:21:55
,第二个文件2013-06-04 11:21:55
在同一行中,因此我想将输出设为27。即27秒。
Can some one help me with a Unix command to get this done? 有人可以帮我用Unix命令完成这项工作吗?
https://github.com/hroptatyr/dateutils ddif to the rescue https://github.com/hroptatyr/dateutils ddif进行救援
ddiff 2012-03-01T12:17:00 2012-03-02T14:00:00
=>
92580s
paste -d, a b | while IFS=, read t1 t2
do
echo "$(( $( date -d "$t2" +%s ) - $( date -d "$t1" +%s ) ))"
done
That should do it. 那应该做。
Filenames are assumed to be "a" and "b". 文件名假定为“ a”和“ b”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.