convert month from Aaa to xx in little script with awk

后端 未结 4 530
执笔经年
执笔经年 2021-01-14 01:27

I am trying to report on the number of files created on each date. I can do that with this little one liner:

ls -la foo*.bar|awk \'{print $7, $6}\'|sort|uni         


        
4条回答
  •  忘掉有多难
    2021-01-14 01:59

    Here's the idiomatic way to convert an abbreviated month name to a number in awk:

    $ echo "Feb" | awk '{printf "%02d\n",(index("JanFebMarAprMayJunJulAugSepOctNovDec",$0)+2)/3}'
    02
    
    $ echo "May" | awk '{printf "%02d\n",(index("JanFebMarAprMayJunJulAugSepOctNovDec",$0)+2)/3}'
    05
    

    Let us know if you need more info to solve your problem.

提交回复
热议问题