Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

You cannot use grep itself as a generic colorizing tool. Something like colortail may do what you want.

share|improve this answer

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.

share|improve this answer

Check out, which will print different colors for user-defined strings.

Here is a description from the project: 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 | +:login +:apple
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.