bash - Tailing less with a custom LESSOPEN colorize script -
i've written following script pick out keywords log file , highlight terms:
#!/bin/bash case "$1" in *.log) sed -e "s/\(.*\[error\ \].*\)/\x1b[31m&\x1b[0m/" "$1" \ | sed -e "s/\(.*\[warn\ \ \].*\)/\x1b[33m&\x1b[0m/" \ | sed -e "s/\(.*\[info\ \ \].*\)/\x1b[32m&\x1b[0m/" \ | sed -e "s/\(.*\[debug\ \].*\)/\x1b[32m&\x1b[0m/" ;; esac
it works ok until try , follow/tail less (shift+f) @ point fails tail new log lines. ideas why?
that colorizes pass argument script. want instead read stdin. wrap case statement in following loop:
while read line; case "$line" in # ... rest of code here esac done
now can pipe script:
tail -f somefile | colorize_script.sh
additional answer:
i had same need several years ago wrote script works grep colorizes matching text instead of hiding non-matching text. if have tcl on system can grab script here: http://wiki.tcl.tk/38096
just copy/paste code (it's 200 lines) empty file , chmod make executable. name cgrep (for color-grep) , put somewhere in executable path. can this:
tail -f somefile | cgrep '.*\[error\s*\].*' -fg yellow -bg red
Comments
Post a Comment