Gents.
Please can u help.
I would like to calculate the days between two dates.
Example file1 ( previous date)
file1 - Input file
9/29/2010 10195
9/29/2010 1057
2/2/2016 10
2/2/2016 10169
2/2/2016 1057
2/3/2016 10005
2/3/2016 10014
In file2 I add the actual date using this code.
awk -v date="$(date +"%m/%d/%Y")" '{print $0, date}' file1 > file2
file2
9/29/2010 10195 05/12/2017
9/29/2010 1057 05/12/2017
2/2/2016 10 05/12/2017
2/2/2016 10169 05/12/2017
2/3/2016 10005 05/12/2017
2/3/2016 10014 05/12/2017
then using this code i get the difference ( number of days) for 2 dates
awk -v q='"' 'BEGIN {OFS= ","}{
c="date -d"q$1q" +%s";c|getline d1;close(c);
c="date -d"q$3q" +%s";c|getline d2;close(c);
printf "%s, %s, %s, %d\n", $1, $2, $3,(d2-d1)/3600/24}' file2 > file3
file3 - Output file, Column 4 is the days between 2 dates.
9/29/2010, 10195, 05/12/2017, 2417
9/29/2010, 1057, 05/12/2017, 2417
2/2/2016, 10, 05/12/2017, 464
2/2/2016, 10169, 05/12/2017, 464
2/3/2016, 10005, 05/12/2017, 463
2/3/2016, 10014, 05/12/2017, 463
It works fine, BUT take a lot time to end.. My input file is a big file and it take very long time to end.
Kindly can you check the code and if it is possible modify it to be faster. Get same output (file3) but more faster.
Appreciate your help