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
signature.asc
Description: OpenPGP digital signature