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
|
any output to:sed G
ls | sed G
man sed
you will seeG
Append's a newline character followed by the contents of the hold space to the pattern space.
You can also use the --group-separator parameter, with an empty value, so it'd just add a new-line.
some-stream | grep --group-separator=
pipe grep output through
awk -F: '{if(f!=$1)print ""; f=$1; print $0;}'
There is no option for this in grep
and I don't think there is a way to do it with xargs
or tr
(I tried), but here is a for loop that will do it (for f in *; do grep -H "1" $f && echo; done
):
[ 11:58 jon@hozbox.com ~/test ]$ for f in *; do grep -H "1" $f && echo; done
a:1
b:1
c:1
d:1
[ 11:58 jon@hozbox.com ~/test ]$ ll
-rw-r--r-- 1 jon people 2B Nov 25 11:58 a
-rw-r--r-- 1 jon people 2B Nov 25 11:58 b
-rw-r--r-- 1 jon people 2B Nov 25 11:58 c
-rw-r--r-- 1 jon people 2B Nov 25 11:58 d
The -H
is to display file names for grep
matches. Change the *
to your own file glob/path expansion string if necessary.
I can't test it with the -A and -B parameters so I can't say for sure but you could try using sed G as mentioned here on Unix StackEx. You'll loose coloring though if that's important.
Try with -c 2; with printing a context I see grep is separating its found o/p