Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@asakasinsky
Forked from liufuyang/tailc
Created January 11, 2018 11:32
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 asakasinsky/ea3a7cf4c421498ff16176928e3b248c to your computer and use it in GitHub Desktop.
Save asakasinsky/ea3a7cf4c421498ff16176928e3b248c 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