Try with
nawk or
gawk instead of
awk.
Code:
awk -v From="03/Jan/2008" -v To="24/Jul/2008"
Defines variables From and To which contain start and end dates.
Code:
function cnvDate(date ,d) {
split(tolower(date), d, "/");
return sprintf("%04.4d%02.2d%02.2d", d[3], month[d[2]], d[1]);
}
This function coverts a date from 'dd/mmm/yyyy' to 'yyyymmdd'.
Code:
BEGIN {
FS = "[:[]";
month["jan"]=1 ; month["feb"]=2 ; month["mar"]=3 ; month["apr"]=4 ;
month["may"]=5 ; month["jun"]=6 ; month["jul"]=7 ; month["aug"]=8 ;
month["sep"]=9 ; month["oct"]=10; month["nov"]=11; month["dec"]=12;
date_from = cnvDate(From);
date_to = cnvDate(To);
}
Initalizations :
- Input field separator ':' or '['
- Months table used by cnvDate function
- Start and end dates format yyyymmdd
Code:
{
date = cnvDate($2)
if (date >= date_from && date <= date_to)
print;
}
For each input line :
- Convert date to format yyyymmdd
- Print line if date between start and end dates
Jean-Pierre.