Skip to content

Instantly share code, notes, and snippets.

@smj10j
Created December 8, 2014 15:35
Show Gist options
  • Save smj10j/6f7ffcf48536aab7941a to your computer and use it in GitHub Desktop.
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
# 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