Last active
May 25, 2016 17:15
-
-
Save blobaugh/a2e4a6e62e32abd010cdc6b7a3a90652 to your computer and use it in GitHub Desktop.
Seperate a PHP log file by date
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
#!/bin/bash | |
# Location of log file is passed in as the first parameter | |
# Get a list of all the dates in the file | |
DATES="$(grep "2016" $1 | cut -d ' ' -f 1 | sort | uniq)" | |
for i in ${DATES}; do | |
# $i contains the string of the date we are looking at | |
# Remove the leading [ to prevent grep regex errors | |
pattern=${i:1} | |
# Grab the day from the file and store it in a new log file | |
echo Building log for $pattern | |
grep $pattern $1 > $pattern.log | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment