Unix awk根据日期范围提取行:

Unix awk根据日期范围提取行:,unix,awk,Unix,Awk,如果日期介于2015年3月25日至2015年5月5日之间,则希望从第二个字段$2中提取行项目。 日期列未排序,每个文件包含数百万条记录 Inputs.gz Des,DateInfo,Amt,Loc,Des2 abc,02-dec-2014,10,def,xyz abc,20-apr-2015,25,def,xyz abc,14-apr-2015,40,def,xyz abc,17-mar-2014,55,def,xyz abc,24-nov-2011,70,def,xyz abc,13-may-

如果日期介于2015年3月25日至2015年5月5日之间,则希望从第二个字段$2中提取行项目。 日期列未排序,每个文件包含数百万条记录

Inputs.gz

Des,DateInfo,Amt,Loc,Des2
abc,02-dec-2014,10,def,xyz
abc,20-apr-2015,25,def,xyz
abc,14-apr-2015,40,def,xyz
abc,17-mar-2014,55,def,xyz
abc,24-nov-2011,70,def,xyz
abc,13-may-2015,85,def,xyz
abc,30-sep-2008,100,def,xyz
abc,20-jan-2014,115,def,xyz
abc,04-may-2015,130,def,xyz
abc,25-nov-2013,145,def,xyz
abc,29-mar-2015,55,def,xyz
我已经尝试了以下命令并完成了:

function getDate(date) {
    split(date, a, "-");
    return mktime(a[3] " " sprintf("%02i",(index("janfebmaraprmayjunjulaugsepoctnovdec", a[2])+2)/3) " " a[1] " 00 00 00")
}

BEGIN {FS=","}

{ if ( getDate($2)>=getDate(25-mar-2015) && getDate($2)<=getDate(05-may-2015) ) print $0 }
请建议。。。我没有perl和python访问权限

表达式getDate25-mar-2015将-1990提供给getDate,因为您没有变量mar,所以它的计算结果为0。用引号将其括起来:getDate25-mar-2015,您可能有机会。表达式getDate25-mar-2015提供了-1990到getDate,因为您没有变量mar,所以它的计算结果为0。用引号括起来:getDate25-mar-2015,你可能有机会。
$ cat tst.awk
function getDate(date,  a) {
    split(date, a, /-/)
    return mktime(a[3]" "(index("janfebmaraprmayjunjulaugsepoctnovdec",a[2])+2)/3" "a[1]" 0 0 0")
}

BEGIN {
    FS=","
    beg = getDate("25-mar-2015")
    end = getDate("05-may-2015")
}

{ cur = getDate($2) }

NR>1 && cur>=beg && cur<=end

$ awk -f tst.awk  file
abc,20-apr-2015,25,def,xyz
abc,14-apr-2015,40,def,xyz
abc,04-may-2015,130,def,xyz
abc,29-mar-2015,55,def,xyz
$ cat tst.awk
function getDate(date,  a) {
    split(date, a, /-/)
    return mktime(a[3]" "(index("janfebmaraprmayjunjulaugsepoctnovdec",a[2])+2)/3" "a[1]" 0 0 0")
}

BEGIN {
    FS=","
    beg = getDate("25-mar-2015")
    end = getDate("05-may-2015")
}

{ cur = getDate($2) }

NR>1 && cur>=beg && cur<=end

$ awk -f tst.awk  file
abc,20-apr-2015,25,def,xyz
abc,14-apr-2015,40,def,xyz
abc,04-may-2015,130,def,xyz
abc,29-mar-2015,55,def,xyz