awk根据日期范围提取行:

VNA*_*VNA 1 unix awk

想要提取行项目,如果日期范围介于25-mar-2015 to 05-may-2015第二个字段之间($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
Run Code Online (Sandbox Code Playgroud)

我试过下面的命令和in-complete:

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 }
Run Code Online (Sandbox Code Playgroud)

预期产出:

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
Run Code Online (Sandbox Code Playgroud)

请建议......我没有perl和python访问权限.

Ed *_*ton 5

$ 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
Run Code Online (Sandbox Code Playgroud)