Created
February 10, 2017 15:51
-
-
Save xenithorb/b723eb81136a5a555943b5d82c637929 to your computer and use it in GitHub Desktop.
tail with highlight for matching lines with color
This file contains hidden or 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
color_tail() { local file="$1"; shift; local awk_cmd="$(count=0; for i in "$@"; do ((count++)); printf '/%s/ {print "\\033[3%sm",$0,"\\033[39m"; next; }\n' "$i" "$count"; done; echo "{ print \$0 }")"; tail -n100 -f "$file" | eval awk \'"${awk_cmd}"\'; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Intent:
Tail a log file and highlight keyword lines
Usage:
This is intended to be used as a bash profile function. Please add it to
~/.bashrc
or equivalent environment files. You can test it by simply copying and pasting it into an interactive terminal session. You may have any number of hightlight words, but only one file.Example: