使用 AWK 增加日期
大家好,我需要你的帮助。我有一个文件“test.csv”,我想增加“6 个月”和“10 天”的日期,以便得到以下输出:
测试.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"
输出 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"
输出 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"
我已经用这个命令试过了:
awk -F"\" ,\" " '{{ cmd="date \"+%Y-%m-%d %T\" -d \""$3" +10 days\""; 命令 | 获取线基准;关闭(cmd);打印 $0 ",\""datum"\""}}' test.csv > test-increment-10days.csv
awk -F"\" ,\" " '{{ cmd="date \"+%Y-%m-%d %T\" -d \""$3" +6 个月\""; 命令 | 获取线基准;关闭(cmd);打印 $0 ",\""datum"\""}}' test.csv > test-increment-6months.csv
但我得到了这个错误的输出。
测试增量 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"
测试增量 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"
“test-increment-10days.csv”中的日期只增加一天,而“test-increment-6months.csv”中的日期只增加一个月。希望有人可以提供帮助。