in reply to Re: grep -A10 oneliner?
in thread grep -A10 oneliner?
Why not both?
# grep -b -A10 pattern file perl -ne '$c=11if/pattern/;$d=$c<11?"-":":";$t||=0;$c--,print"$t$d$_"i +f$c;$t=tell' file
Update: This produces the same output as GNU diff which prints --\n between groups farther than the -A amount of lines apart.
perl -lne 'if(/pattern/){print"--"if!$c&&$t;$c=11};$d=$c<11?"-":":";$t +||=0;$c--,print"$t$d$_"if$c;$t=tell' file
|
|---|