Subject: bug#26576: closed (Re: bug#26576: -v when used with -C)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 20 Apr 2017 14:58:02 +0000

Your bug report

#26576: -v when used with -C

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
26576: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=26576
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#26576: -v when used with -C
From: Eric Blake <[email-masked]>
To: 積丹尼 Dan Jacobson <[email-masked]>, [email-masked]
Date: Thu, 20 Apr 2017 09:56:56 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

tag 26576 notabug
thanks

On 04/20/2017 09:39 AM, 積丹尼 Dan Jacobson wrote:
> You know if this only gets five lines,
> grep -C 2    ZZZ 00001.vcf|wc - 00001.vcf
>       5       5     197 -
>    1686    1731   83630 00001.vcf
> then this
> grep -C 2 -v ZZZ 00001.vcf|wc - 00001.vcf
>    1686    1731   83630 -
>    1686    1731   83630 00001.vcf
> should get all EXCEPT five lines.

Not necessarily true.  Let's simplify your example to something that
doesn't require knowing the contents of 00001.vcf:

$ seq 10 | grep -C 2    5
3
4
5
6
7

That says show all lines that match the regex '5', as well as (up to) 2
context lines on either side.  So we get a total output of five lines,
even though only one of those five lines actually matched.

Now the converse:

$ seq 10 | grep -C 2 -v 5
1
2
3
4
5
6
7
8
9
10

That says to show all lines that do not match the regex '5', as well as
(up to) 2 context lines on either side.  So we get a total output of ten
lines, but that is comprised of 4 matching lines, 1 context line, and 5
more matching lines (grep was smart enough to consolidate the two tail
lines after 4 and the two head lines before 6 into a single output line,
rather than displaying two independent chunks).

For further proof that -C and -v are correctly working together, try
something that excludes enough context lines to actually get two hunks:

$ seq 10 | grep -C 2 -v '[3-8]'
1
2
3
4
--
7
8
9
10

Now you're matching 2 lines, then 2 lines tail context, then a hunk
separator, then 2 lines head context, then 2 more matching lines.

Therefore, I'm tagging this as not a bug.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Subject: -v when used with -C
From: 積丹尼 Dan Jacobson <[email-masked]>
To: [email-masked]
Date: Thu, 20 Apr 2017 22:39:28 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

You know if this only gets five lines,
grep -C 2    ZZZ 00001.vcf|wc - 00001.vcf
      5       5     197 -
   1686    1731   83630 00001.vcf
then this
grep -C 2 -v ZZZ 00001.vcf|wc - 00001.vcf
   1686    1731   83630 -
   1686    1731   83630 00001.vcf
should get all EXCEPT five lines.