linux - [Solved-5 Solutions] How to grep a continuous stream - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
Is that possible to use grep on a continuous stream ?
Linux - Solution 1:
Turn on grep's line buffering mode.
Linux - Solution 2:
You can use the tail -f <file> | grep <pattern> all the time.
It will wait till grep flushes, not till it finishes.
Linux - Solution 3:
grep uses some output buffering. You can try
Linux - Solution 4:
You can tail -f /var/log/some.log |grep foo and it will work just fine.
If you need to use multiple greps on a running log file and you find that you get no output, you may need to stick the --line-buffered switch into your middle grep(s), like so:
Linux - Solution 5:
-F is better in case of file rotate (-f will not work properly if file rotated)
-A and -B is useful to get lines just before and after the pattern occurrence .. these blocks will appeared between dashed line separators