Add blank line after every result in grep

grep, linux, scripting

Solution

Pipe `|` any output to:

sed G

Example:

ls | sed G

If you `man sed` you will see

`G` Append's a newline character followed by the contents of the hold space to the pattern space.

Problem

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 file1:line4 file1:line5 file1:line6 </blank line> file2:line1 file2:line2 file2:line3 file2:pattern file2:line4 file2:line5 file2:line6 ``` 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. also note that adding a new blank line after every bb+aa+1 line won't work because what if a file has less than bb lines before the pattern.

Original source