I have some output of my program:
# php check.php | grep -E "rule_1|rule_4"
I would like results equaling to rule_1 to be red and results equaling to rule_4 to be blue.
Is this possible, because at this moment, everything is colored red.
I have some output of my program:
# php check.php | grep -E "rule_1|rule_4"
I would like results equaling to rule_1 to be red and results equaling to rule_4 to be blue.
Is this possible, because at this moment, everything is colored red.
Try this:
alias egrep="grep -E --color=never"
alias egrep-grey=" GREP_COLOR='1;30' grep -E --color=always"
alias egrep-red=" GREP_COLOR='1;31' grep -E --color=always"
alias egrep-green=" GREP_COLOR='1;32' grep -E --color=always"
alias egrep-yellow=" GREP_COLOR='1;33' grep -E --color=always"
alias egrep-blue=" GREP_COLOR='1;34' grep -E --color=always"
alias egrep-magenta="GREP_COLOR='1;35' grep -E --color=always"
alias egrep-cyan=" GREP_COLOR='1;36' grep -E --color=always"
alias egrep-white=" GREP_COLOR='1;37' grep -E --color=always"
php check.php | egrep "rule_1|rule_4" | egrep-red "rule_1|$" | egrep-blue "rule_4|$"
You can do this with a regex parser like flex. But keep in mind that some patterns can be interpreted in unintuitive ways (e.g. if your parser is matching the longest pattern vs the shortest). For example the pattern ..1|aaa1
and the input aaaa1
will usually match ..1
.
Check out colorize.pl, which will print different colors for user-defined strings.
Here is a description from the colorize.pl project:
Colorize.pl is a short script that reads from stdin and writes to stdout. Rows that match a user's search strings will be colorized with user-defined colors. Command line options are available. Colorization is done via ANSI escape codes.
On my Apple MacBook Pro, the following will print 'login' in read, and 'apple' in green:
tail /var/log/system.log | colorize.pl +:login +:apple