RAKESH M
RAKESH M

Reputation: 153

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. 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.

Can some one help me with a Unix command to get this done?

Upvotes: 1

Views: 73

Answers (2)

user80168
user80168

Reputation:

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".

Upvotes: 1

cggaurav
cggaurav

Reputation: 575

https://github.com/hroptatyr/dateutils ddif to the rescue

ddiff 2012-03-01T12:17:00 2012-03-02T14:00:00
=>
  92580s

Upvotes: 1

Related Questions