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.
2 Answers
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.– PeteNov 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– PeteNov 13, 2013 at 19:57
-
The matches are highlighted with your command. So what is your desired output?– ManoloNov 13, 2013 at 20:01
-
Well, I think I understand you now, since I've seen @garyjohn answer. Is it your desired behavior?– ManoloNov 13, 2013 at 20:04
tail
, rungrep somepattern
directly. Could you give an example of the kind of process you are monitoring?