How to 'grep' a continuous stream?

前端 未结 12 1497
清酒与你
清酒与你 2020-11-22 11:15

Is that possible to use grep on a continuous stream?

What I mean is sort of a tail -f command, but with grep on t

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 11:35

    you may consider this answer as enhancement .. usually I am using

    tail -F  | grep --line-buffered   -A 3 -B 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

    But For me I prefer doing the following

    tail -F  | less
    

    this is very useful if you want to search inside streamed logs. I mean go back and forward and look deeply

提交回复
热议问题