Last active
August 29, 2015 14:03
-
-
Save chernjie/47e25bc3666c00d62d32 to your computer and use it in GitHub Desktop.
Split log file by date
This file contains hidden or 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
#!/bin/bash | |
function breakup() | |
{ | |
LAST=$(wc -l "$1" | xargs | cut -d' ' -f1) | |
LAST=$(($LAST + 1)) | |
grep -no ^201.-..-.. "$1" | sort -u -t: -k2 | sort -t: -rnk1 | while read j | |
do | |
DATE=$(echo $j | cut -d: -f2) | |
LINE=$(echo $j | cut -d: -f1) | |
echo "$1-${DATE//-/}" | |
sed -n $LINE,$(($LAST - 1))p "$1" > "$1-${DATE//-/}" | |
LAST=$LINE | |
done | |
} | |
for file | |
do | |
breakup $file | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment