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.

  • 1
    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, 2013 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, 2013 at 19:54

2 Answers 2


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
  • Not sure why I didn't try this, I just assumed the context arguments wouldn't work on streams. Thanks.
    – Pete
    Nov 13, 2013 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.

  • 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, 2013 at 19:57
  • The matches are highlighted with your command. So what is your desired output?
    – Manolo
    Nov 13, 2013 at 20:01
  • Well, I think I understand you now, since I've seen @garyjohn answer. Is it your desired behavior?
    – Manolo
    Nov 13, 2013 at 20:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .