Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
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 '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
add comment

2 Answers 2

up vote 1 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
add comment

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
add comment

Your Answer

 
discard

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.