Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a quite large apache logfile (2,5 G). Its that big because i havent used logrotate until now. Now the logs get rotated corretly but i want the rotation (one logfile per month) for the time until now so i have to "rotate" the old logfile.

Does anyone know how i could do that ? (some script that splits my logfile per month ?)

Thanks in advance,


share|improve this question

migrated from stackoverflow.com Feb 27 '12 at 3:50

This question came from our site for professional and enthusiast programmers.

Use awk to find the month boundaries, then use csplit to split by context.

sample data:

1-1  ...
1-15 ...
1-30 ...
2-1  ...
2-15 ...
2-29 ...
3-2  ...
3-20 ...

run command

$ cat log | awk -F- 'x!=$1{x=$1; print "MONTH"}1' | csplit - /MONTH/ '{*}'

delete first line

$ sed -i 1d xx*
share|improve this answer

LoadModule log_rotate_module modules/mod_log_rotate.so

CustomLog site.%m-.access.log


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.