Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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 log file and would like to cut it into copies of 15min. In the log file the lines start with:

dd mmm yyyy hh:mm:ss,xxx 


12 Feb 2013 16:05:02,xxx log text...

and the file rotates every hour so I would like to take a copy of the log file, split it into 15min of logging and have say 4 log files.

share|improve this question
cut doesn't support completely regexr , So use awk.Also cut have probelm with space.awk solved it. – PersianGulf Feb 14 '13 at 4:05
You might check cronosplit to split the files out. – Jodie C Feb 14 '13 at 4:15
For obvious reasons, being able to split into 20-minute pieces would make this a lot easier. (In case that 15-minutes requirement isn't set in stone.) – Ulrich Schwarz Feb 14 '13 at 5:33
A regex for grep could select a range of time from a log. But you will have to adjust it for each time range, for each day. Scripting this would give you more iterative control over the lines you process. Let me suggest Python. – invert Feb 14 '13 at 6:08


cat input |
    awk -F ':' '{if ($2 < 15) {print $0 > "15.log"} else print}' |
    awk -F ':' '{if ($2 < 30) {print $0 > "30.log"} else print}' |
    awk -F ':' '{if ($2 < 45) {print $0 > "45.log"} else print}' |
    cat > 60.log
share|improve this answer

Maybe this one does the job:

cat $INNAME | grep -v '^$' |
while read r; do
  LOG_NUM=$(($(echo $r | cut -d' ' -f4 | cut -d':' -f2 | cut -d',' -f1)/15));
  [ "$r" ] && echo $r >> $OUTNAME.$LOG_NUM;

cronosplit is probably the way to go. but if you need a fast "one-time"-solution. you'll maybe happier with the "one-liner".

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.