Increment date with AWK
Hi all, I need your help. I have a file "test.csv" and I want to increase the dates for "6 months" and "10 days" so that I am getting the following output:
test.csv:
"000001","TEST1","2013-05-07 16:02:07","ACTIVE"
"000003","TEST3","2013-05-09 16:02:07","ACTIVE"
"000004","TEST4","2013-05-10 16:02:07","ACTIVE"
"000005","TEST5","2013-05-11 12:02:07","ACTIVE"
Output test-increment-10days.csv:
"000001","TEST1","2013-05-07 16:02:07","ACTIVE","2013-05-17 16:02:07"
"000003","TEST3","2013-05-09 16:02:07","ACTIVE","2013-05-19 16:02:07"
"000004","TEST4","2013-05-10 16:02:07","ACTIVE","2013-05-20 16:02:07"
"000005","TEST5","2013-05-11 12:02:07","ACTIVE","2013-05-21 12:02:07"
Output test-increment-6months.csv:
"000001","TEST1","2013-05-07 16:02:07","ACTIVE","2013-11-07 16:02:07"
"000003","TEST3","2013-05-09 16:02:07","ACTIVE","2013-11-09 16:02:07"
"000004","TEST4","2013-05-10 16:02:07","ACTIVE","2013-11-10 16:02:07"
"000005","TEST5","2013-05-11 12:02:07","ACTIVE","2013-11-11 12:02:07"
I have tried it with this commands:
awk -F"","" '{{ cmd="date "+%Y-%m-%d %T" -d ""$3" +10 days""; cmd | getline datum; close(cmd); print $0 ",""datum"""}}' test.csv > test-increment-10days.csv
awk -F"","" '{{ cmd="date "+%Y-%m-%d %T" -d ""$3" +6 months""; cmd | getline datum; close(cmd); print $0 ",""datum"""}}' test.csv > test-increment-6months.csv
but I am getting this wrong outputs.
test-increment-10days.csv:
"000001","TEST1","2013-05-07 16:02:07","ACTIVE","2013-05-08 16:02:07"
"000003","TEST3","2013-05-09 16:02:07","ACTIVE","2013-05-10 16:02:07"
"000004","TEST4","2013-05-10 16:02:07","ACTIVE","2013-05-11 16:02:07"
"000005","TEST5","2013-05-11 12:02:07","ACTIVE","2013-05-12 12:02:07"
test-increment-6months.csv:
"000001","TEST1","2013-05-07 16:02:07","ACTIVE","2013-06-07 16:02:07"
"000003","TEST3","2013-05-09 16:02:07","ACTIVE","2013-06-09 16:02:07"
"000004","TEST4","2013-05-10 16:02:07","ACTIVE","2013-06-10 16:02:07"
"000005","TEST5","2013-05-11 12:02:07","ACTIVE","2013-06-11 12:02:07"
The dates in "test-increment-10days.csv" are only incremented one day and in the "test-increment-6months.csv" only one month. Hope somebody can help.
See Question&Answers more detail:
os