Skip to content

Instantly share code, notes, and snippets.

@blobaugh
Last active May 25, 2016 17:15
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 blobaugh/a2e4a6e62e32abd010cdc6b7a3a90652 to your computer and use it in GitHub Desktop.
Save blobaugh/a2e4a6e62e32abd010cdc6b7a3a90652 to your computer and use it in GitHub Desktop.
Seperate a PHP log file by date
#!/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