Skip to content

Instantly share code, notes, and snippets.

@djkeh
Forked from liufuyang/tailc
Created November 28, 2019 04:12
Show Gist options
  • Save djkeh/8f987c419c309585bdf610943e09c282 to your computer and use it in GitHub Desktop.
Save djkeh/8f987c419c309585bdf610943e09c282 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