Skip to content

Instantly share code, notes, and snippets.

@shamrin
Last active December 25, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamrin/6978117 to your computer and use it in GitHub Desktop.
Save shamrin/6978117 to your computer and use it in GitHub Desktop.
#!/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