Super User is a question and answer site for computer enthusiasts and power users. 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 often use tail -f | grep someregex on log files. I have grep liased to grep ---color=auto so my matches are highlighted. If I want to see my matches in the context of the whole stream, how would I go about that? Essentially, I want to use tail + grep as a highlighter.

share|improve this question
Could you please clarify? What do you mean by the whole stream? If you want the whole stream, just don't use tail, run grep somepattern directly. Could you give an example of the kind of process you are monitoring? – terdon Nov 13 '13 at 19:49
if I am tailing a log file, grepping on error messages, but want to see it in context of some debug messages leading up to that match, in real time. – Pete Nov 13 '13 at 19:54
up vote 2 down vote accepted

To see your matches in context, use the -C option. To see all the lines, use a huge argument to -C, e.g.,

tail -f yourlogfile | grep -C9999 someregex
share|improve this answer
Not sure why I didn't try this, I just assumed the context arguments wouldn't work on streams. Thanks. – Pete Nov 13 '13 at 20:05

If I understand well, it is what you are looking for:

grep "someregex" yourFile

It will print the lines where the "regex" matches.

share|improve this answer
I'm using this on a log file, I would like to see it output in real time w/o interaction, hence the tail -f, but want to highlight matches – Pete Nov 13 '13 at 19:57
The matches are highlighted with your command. So what is your desired output? – Manolo Nov 13 '13 at 20:01
Well, I think I understand you now, since I've seen @garyjohn answer. Is it your desired behavior? – Manolo Nov 13 '13 at 20:04

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.