Add blank line after every result in grep

前端 未结 7 1983
北荒
北荒 2020-12-14 18:24

my grep command looks like this zgrep -B bb -A aa \"pattern\" *

I would lke to have output as:

file1:line1
file1:line2
file1:line3
file1:pattern
file         


        
相关标签:
7条回答
  • 2020-12-14 19:13

    The problem is that its hard to distinguish when lines corresponding to the first found result end and the lines corresponding to the second found result start.

    Note that although man grep says that "--" is added between contiguous group of matches. It works only when multiple matches are found in the same file. but in my search (as above) I am searching multiple files.

    If you don't mind a -- in lieu of a </blank line>, add the -0 parameter to your grep/zgrep command. This should allow for the -- to appear even when searching multiple files. You can still use the -A and -B flags as desired.

    0 讨论(0)
提交回复
热议问题