Last active
December 25, 2015 12:39
-
-
Save shamrin/6978117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
NLINES=2 | |
IFS='' # force `read line` to take whole lines | |
LOG_PREFIX=$1 | |
if test X$LOG_PREFIX = X; then | |
echo usage: $0 "<log-prefix>" | |
exit 1 | |
fi | |
I=0 | |
N=0 | |
cat | grep foo | while read line; do | |
if test $I = $NLINES; then | |
mv $LOG_PREFIX$N.working.log $LOG_PREFIX$N.log | |
I=0 | |
N=$(expr $N + 1) | |
fi | |
echo $line >> $LOG_PREFIX$N.working.log | |
I=$(expr $I + 1) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment