Awk to find lines within date range in a file with custom date format

后端 未结 2 1690
野趣味
野趣味 2021-01-16 07:06

I\'m trying to find all lines between a date range in a file. However dates are formatted in a non standard way. Is there a way for awk to read these? The log file is format

2条回答
  •  不思量自难忘°
    2021-01-16 07:28

    $ cat tst.awk
    {
        mthNr = (index("JanFebMarAprMayJunJulAugSepOctNovDec",$1)+2)/3
        date  = sprintf("%02d%02d", mthNr, $2)
    }
    (date >= from) && (date <= to)
    
    $ awk -v from='0101' -v to='0210' -f tst.awk file
    Jan  5 11:34:00 log messages here
    Jan 13 16:21:00 log messages here
    Feb  1 01:14:00 log messages here
    Feb 10 16:32:00 more messages
    

    Massage to suit...

提交回复
热议问题