Skip to content

Instantly share code, notes, and snippets.

@cornerot
Forked from liufuyang/tailc
Created November 27, 2019 16:09
Show Gist options
  • Save cornerot/e6f1236d9d1780e080d1f3a9bd20cfd3 to your computer and use it in GitHub Desktop.
Save cornerot/e6f1236d9d1780e080d1f3a9bd20cfd3 to your computer and use it in GitHub Desktop.
Color output of linux tail command
#!/bin/bash
# save this file as tailc then
# run as: $ tailc logs/supplier-matching-worker.log Words_to_highlight
file=$1
if [[ -n "$2" ]]; then
color='
// {print "\033[37m" $0 "\033[39m"}
/(WARN|WARNING)/ {print "\033[1;33m" $0 "\033[0m"}
/(ERROR|CRIT)/ {print "\033[1;31m" $0 "\033[0m"}
/('$2')/ {print "\033[1;32m" $0 "\033[0m"}
'
else
color='
// {print "\033[37m" $0 "\033[39m"}
/(WARN|WARNING)/ {print "\033[1;33m" $0 "\033[0m"}
/(ERROR|CRIT)/ {print "\033[1;31m" $0 "\033[0m"}
'
fi
tail -5000f $file | awk "$color"
# Colors
# 30 - black 34 - blue 40 - black 44 - blue
# 31 - red 35 - magenta 41 - red 45 - magenta
# 32 - green 36 - cyan 42 - green 46 - cyan
# 33 - yellow 37 - white 43 - yellow 47 - white
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment