Created
December 8, 2014 15:35
-
-
Save smj10j/6f7ffcf48536aab7941a to your computer and use it in GitHub Desktop.
Bash one-liners to find first and last occurences of errors in server logs
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
# find the first occurrence of each Fatal error | |
grep "Fatal" combined | awk '{FS="(error: )|( in \/mnt)|( - \/mnt)"} {errors[$2]=$0} END {for(i in errors) print errors[i]}' | |
# find the last occurrence of each fatal error | |
grep "Fatal" <(tac combined) | awk '{FS="(error: )|( in \/mnt)|( - \/mnt)"} {errors[$2]=$0} END {for(i in errors) print errors[i]}' | |
# find the first occurence of each fatal error, sorted by date | |
grep "Fatal" combined | awk '{FS="(error: )|( in \/mnt)|( - \/mnt)"} {errors[$2]=$0} END {for(i in errors) print errors[i]}' | sort -k1 | egrep "^2014[^a-z]+ " | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment