How to split existing apache logfile by month?

后端 未结 1 1663
迷失自我
迷失自我 2021-02-03 12:47

How can one split existing apache logfiles into separate files by month?

I\'ve scoured the web and I can\'t find anything. Yes, I know about logrotate and cronolog and

相关标签:
1条回答
  • 2021-02-03 13:22

    One way using awk:

    awk '{ split($4,array,"/"); print > array[2] ".txt" }' file.txt
    

    This will output files like:

    May.txt
    June.txt
    July.txt
    etc
    

    EDIT:

    Perhaps you would like to keep the years separate:

    awk '{ split($4,array,"[:/]"); print > array[2] array[3] ".txt" }' file.txt
    

    This will output files like:

    May2011.txt
    May2012.txt
    July2011.txt
    etc
    
    0 讨论(0)
提交回复
热议问题