0

This question already has an answer here:

Job1 07/09/2018 22:40:57  01/20/2019 11:48:52  
Job2 11/28/2018 19:23:49  01/20/2019 05:29:49  
Job3 10/10/2018 01:51:52  01/19/2019 23:08:13  
Job4 12/08/2018 20:51:34  01/19/2019 22:04:26  
Job5 12/24/2018 01:52:07  01/20/2019 05:29:31  

Extract 2 dates from the outputs and find the difference between the 2 dates from the respective columns, I wanted to know the most ran job.

I ran this script:

awk 'NR>1 {print $2,$3,$4,$5}' pools.txt  | while read d1 t1 d2 t2; do
  i1=$(date -u -d "20$d1 $t1" +%s)
  i2=$(date -u -d "20$d1 $t2" +%s)
  date -d @"$((i1-i2))" +%M:%S;
done

but I got this error because the date format is little different here:

date: invalid date `2011/28/2018 19:23:49'

date: invalid date `2011/28/2018 05:29:49' 30:00

marked as duplicate by Thomas, Jeff Schaller, terdon awk Jan 20 at 13:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
  • But don't you need a pure awk solution? That was given here: Get time difference of two dates using awk. But if you don't understand awk well enough to fix the script in your question, then why would you insist on using awk? – terdon Jan 20 at 14:41
  • Anyway, just remove the 20 from the bash script and it will work fine: awk 'NR>1 {print $2,$3,$4,$5}' pools.txt | while read d1 t1 d2 t2; do i1=$(date -u -d "$d1 $t1" +%s); i2=$(date -u -d "$d1 $t2" +%s); date -d @"$((i1-i2))" +%M:%S; done – terdon Jan 20 at 14:42
  • I couldn't remove '20' because that was from the standard output. – Vishwanath Dalawai Jan 20 at 14:55
  • Is the question about finding the difference between dates (it's a duplicate) or about the reason for your own script failing (not a duplicate)? – roaima Jan 20 at 16:56