From unknown Sun Jun 22 11:33:20 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#26576 <26576@debbugs.gnu.org> To: bug#26576 <26576@debbugs.gnu.org> Subject: Status: -v when used with -C Reply-To: bug#26576 <26576@debbugs.gnu.org> Date: Sun, 22 Jun 2025 18:33:20 +0000 retitle 26576 -v when used with -C reassign 26576 grep submitter 26576 =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson severity 26576 normal tag 26576 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 10:39:53 2017 Received: (at submit) by debbugs.gnu.org; 20 Apr 2017 14:39:53 +0000 Received: from localhost ([127.0.0.1]:59102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DFR-0006T8-AS for submit@debbugs.gnu.org; Thu, 20 Apr 2017 10:39:53 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43816) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DFP-0006Su-49 for submit@debbugs.gnu.org; Thu, 20 Apr 2017 10:39:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1DFJ-0002bX-2W for submit@debbugs.gnu.org; Thu, 20 Apr 2017 10:39:45 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:54523) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1DFI-0002bT-VG for submit@debbugs.gnu.org; Thu, 20 Apr 2017 10:39:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1DFH-00023V-P1 for bug-grep@gnu.org; Thu, 20 Apr 2017 10:39:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1DFC-0002W0-R5 for bug-grep@gnu.org; Thu, 20 Apr 2017 10:39:43 -0400 Received: from homie.mail.dreamhost.com ([208.97.132.208]:41649 helo=homiemail-a8.g.dreamhost.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d1DFC-0002Rk-IB for bug-grep@gnu.org; Thu, 20 Apr 2017 10:39:38 -0400 Received: from homiemail-a8.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a8.g.dreamhost.com (Postfix) with ESMTP id 9D42F5F206A for ; Thu, 20 Apr 2017 07:39:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to :subject:date:message-id:mime-version:content-type; s= jidanni.org; bh=hme7fQSBJQ+wiBdfyONUmB+58XM=; b=lw9wqllmr2ZA9vip 7H82v9ae4vQNm+WG6Av+Ajw9uc4g8i3dYZ4HX4BYWPTPGYuodGFLEWMzgKqr4jLS jTrdekI24u5Jak3rpbSqXFr2UP1N6UoUttTwC8VoYOklzPjfz6j7Z6ZgHZcEA0Ac X4TjSMD06TBaqUIdkeF4U5fXTmo= Received: from jidanni.org (111-246-102-19.dynamic-ip.hinet.net [111.246.102.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jidanni@jidanni.org) by homiemail-a8.g.dreamhost.com (Postfix) with ESMTPSA id 5A19E5F2069 for ; Thu, 20 Apr 2017 07:39:33 -0700 (PDT) From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson To: bug-grep@gnu.org Subject: -v when used with -C Date: Thu, 20 Apr 2017 22:39:28 +0800 Message-ID: <87o9vr16u7.fsf@jidanni.org> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) 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. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 10:57:06 2017 Received: (at control) by debbugs.gnu.org; 20 Apr 2017 14:57:06 +0000 Received: from localhost ([127.0.0.1]:59112 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DW6-0006sM-3E for submit@debbugs.gnu.org; Thu, 20 Apr 2017 10:57:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38974) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DW4-0006rn-Bl; Thu, 20 Apr 2017 10:57:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE3A375EAE; Thu, 20 Apr 2017 14:56:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CE3A375EAE Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CE3A375EAE Received: from [10.10.121.102] (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BAAB80B2D; Thu, 20 Apr 2017 14:56:57 +0000 (UTC) Subject: Re: bug#26576: -v when used with -C To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= , 26576-done@debbugs.gnu.org References: <87o9vr16u7.fsf@jidanni.org> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <92a31189-be6a-6aac-eaf9-25a829bebe4c@redhat.com> Date: Thu, 20 Apr 2017 09:56:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <87o9vr16u7.fsf@jidanni.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="MDuP9f3Qd0a32XXGTA5cPDacn1SENaMFw" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Apr 2017 14:56:58 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --MDuP9f3Qd0a32XXGTA5cPDacn1SENaMFw Content-Type: multipart/mixed; boundary="ITVnRFppl4euALpulUMAkR7jkPxedtSTf"; protected-headers="v1" From: Eric Blake To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= , 26576-done@debbugs.gnu.org Message-ID: <92a31189-be6a-6aac-eaf9-25a829bebe4c@redhat.com> Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> In-Reply-To: <87o9vr16u7.fsf@jidanni.org> --ITVnRFppl4euALpulUMAkR7jkPxedtSTf Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable tag 26576 notabug thanks On 04/20/2017 09:39 AM, =E7=A9=8D=E4=B8=B9=E5=B0=BC 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. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --ITVnRFppl4euALpulUMAkR7jkPxedtSTf-- --MDuP9f3Qd0a32XXGTA5cPDacn1SENaMFw Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJY+Mw4AAoJEKeha0olJ0Nqg44H/11hSerQgDfYFgDLmeaTS3Hy uXjvr35OJUZvOtZMIgnUKBcPgM36v2vi8byrtclkvjXJPdZGBy2t6CXD24LENYQw IeZ57xhHI6z/P8wUjoNVVB4udWYjM+YdXrHuWz/+yxdDBiVmLamcMoa+EV/Cs4RG XIGben4PtAitk69SzEsaBbfJ3Wn95qV/0LFsXW53KmT65bxJoo7BOZisR3ndVagx cKDq3KJc9JKgDQytipAxfYkGCMMIXdbzLO695qv83rbpjq6a2f6mjuuT6pL/XsvL +0IotOC3HC85abz94YwqAtWaZrITY3sWdhFnvaU/j5XRTiWvnAVLFOVhj3kp+zs= =bQe2 -----END PGP SIGNATURE----- --MDuP9f3Qd0a32XXGTA5cPDacn1SENaMFw-- From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 11:14:32 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 15:14:32 +0000 Received: from localhost ([127.0.0.1]:59145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Dmx-0000h2-SQ for submit@debbugs.gnu.org; Thu, 20 Apr 2017 11:14:31 -0400 Received: from homie.mail.dreamhost.com ([208.97.132.208]:32845 helo=homiemail-a3.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Dmw-0000gu-7X for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 11:14:30 -0400 Received: from homiemail-a3.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a3.g.dreamhost.com (Postfix) with ESMTP id 31E60284093; Thu, 20 Apr 2017 08:14:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to:cc :subject:references:date:message-id:mime-version:content-type; s=jidanni.org; bh=FYpjFWaThEOBi9QU00qJRH3+I8o=; b=eNbYFOGfwqvHy QyC2r3/4Rdxtg67mKWjLunNTkxKzxch7WuhVVqo/+z5pwaCsBsNeVtat3K1wopmz vWPCFuy0b6qVOeerjSkyN+EDK9pezILsFzspUr0UeFkbkqdNdWzsWzgqgBaJYDWv LO1boRLIeSUyYzGYdD1DZYznmFhxyY= Received: from jidanni.org (111-246-102-19.dynamic-ip.hinet.net [111.246.102.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jidanni@jidanni.org) by homiemail-a3.g.dreamhost.com (Postfix) with ESMTPSA id D523B284092; Thu, 20 Apr 2017 08:14:28 -0700 (PDT) From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson To: Eric Blake Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> Date: Thu, 20 Apr 2017 23:14:24 +0800 Message-ID: <87k26f157z.fsf@jidanni.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Mmmm, OK, but grep still needs an additional future option to print just the missing set... From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 11:21:11 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 15:21:11 +0000 Received: from localhost ([127.0.0.1]:59164 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DtP-0000tD-2Q for submit@debbugs.gnu.org; Thu, 20 Apr 2017 11:21:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44420) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1DtN-0000sz-KN for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 11:21:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FFDE338862; Thu, 20 Apr 2017 15:21:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8FFDE338862 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8FFDE338862 Received: from [10.10.121.102] (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FC60189F3; Thu, 20 Apr 2017 15:21:02 +0000 (UTC) Subject: Re: bug#26576: -v when used with -C To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= References: <87o9vr16u7.fsf@jidanni.org> <87k26f157z.fsf@jidanni.org> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <72311847-3001-a741-ca4f-d53b905010f2@redhat.com> Date: Thu, 20 Apr 2017 10:21:02 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <87k26f157z.fsf@jidanni.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="thKka7FMnGEdP97RD3R4gLTbfDb4nGEpt" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 20 Apr 2017 15:21:03 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --thKka7FMnGEdP97RD3R4gLTbfDb4nGEpt Content-Type: multipart/mixed; boundary="LtG9CUT1fHd0Jk7VPbUNPP6FlGMRmmlrf"; protected-headers="v1" From: Eric Blake To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= Cc: 26576-done@debbugs.gnu.org Message-ID: <72311847-3001-a741-ca4f-d53b905010f2@redhat.com> Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> <87k26f157z.fsf@jidanni.org> In-Reply-To: <87k26f157z.fsf@jidanni.org> --LtG9CUT1fHd0Jk7VPbUNPP6FlGMRmmlrf Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 04/20/2017 10:14 AM, =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson wrote: > Mmmm, OK, but grep still needs an additional future option to print jus= t > the missing set... What output are you wanting? If all you want is the non-matching lines, don't ask for context (since the context will include matching lines). If you want your request to be acted on, please demonstrate with some sample input and the resulting output you want to accomplish, and then we can help you figure out if that particular output can already be generated using existing options. But your vague request to "print just the missing set" doesn't tell me what you really want. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --LtG9CUT1fHd0Jk7VPbUNPP6FlGMRmmlrf-- --thKka7FMnGEdP97RD3R4gLTbfDb4nGEpt Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJY+NHeAAoJEKeha0olJ0NqDXIH/jmNqa5CCrDvALmC4T8G5yxZ kaVZTufZy15cgFpb2O9c/oZ/q4hlM0/7TydEWh/LpNhFaf8H3WAOjb6m1Dt9IGpK VZ33zv01xZNMOaBmcA7KJykl/N/wlONrknCpmptb0qJfK80SyQ4gdhN97JbcnugI 9AZsjJ0kGJBGdnbsfjREo+UZLicSDiMDCPuenfOhrxEqEczufWwBOuMszCP454cd ZbNPd8GaX2dZAKigNku6Jg3q2PzzvslFGPqveSUQr1nc1vbsJ7PJcQ1SOdmDkRXm rxb0Ezk00oNcEl8jGY26C6PSjpOR5oF5+l8ZMRu1uiwnfWswVc1ri3nd/swCCbk= =FZDH -----END PGP SIGNATURE----- --thKka7FMnGEdP97RD3R4gLTbfDb4nGEpt-- From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 11:37:11 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 15:37:11 +0000 Received: from localhost ([127.0.0.1]:59184 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1E8t-0001IC-6e for submit@debbugs.gnu.org; Thu, 20 Apr 2017 11:37:11 -0400 Received: from homie.mail.dreamhost.com ([208.97.132.208]:45312 helo=homiemail-a3.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1E8s-0001I5-4L for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 11:37:10 -0400 Received: from homiemail-a3.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a3.g.dreamhost.com (Postfix) with ESMTP id 355D5284091; Thu, 20 Apr 2017 08:37:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to:cc :subject:references:date:message-id:mime-version:content-type; s=jidanni.org; bh=b8KSDHXudUTSVPvXpUOFhvu+jjQ=; b=eYpW1gNYLKifo hC2oagHP+rMAaZ1IS2ve4RPiOosQ3neogz8XsdysOVEkKnIs960DUaBa3i4GpAK+ e/czF5CYqLpYipoMWXC8c16wqQLVsjzDi24rQLPoCvsImOaZSqkBWlZ7l/xsGWAJ d6fOb6vCepIzk+G/h/71jMlpBjTWIg= Received: from jidanni.org (111-246-102-19.dynamic-ip.hinet.net [111.246.102.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jidanni@jidanni.org) by homiemail-a3.g.dreamhost.com (Postfix) with ESMTPSA id E7A7F284078; Thu, 20 Apr 2017 08:37:08 -0700 (PDT) From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson To: Eric Blake Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> Date: Thu, 20 Apr 2017 23:37:03 +0800 Message-ID: <87d1c71468.fsf@jidanni.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) I want to do $ cat file|some_program but I must must exclude the UGLY line and its two neighbors. OK I have found the UGLY line, and its two neighbors $ grep -C 2 UGLY file bla bla UGLY bla bla but I have no way to exclude them before piping to some_program. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 12:26:57 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 16:26:57 +0000 Received: from localhost ([127.0.0.1]:59246 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Ev3-0002Xc-62 for submit@debbugs.gnu.org; Thu, 20 Apr 2017 12:26:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57300) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Ev1-0002XN-Jx for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 12:26:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6968E7573C; Thu, 20 Apr 2017 16:26:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6968E7573C Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6968E7573C Received: from [10.10.121.102] (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5FD882781; Thu, 20 Apr 2017 16:26:47 +0000 (UTC) Subject: Re: bug#26576: -v when used with -C To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= References: <87o9vr16u7.fsf@jidanni.org> <87d1c71468.fsf@jidanni.org> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: Date: Thu, 20 Apr 2017 11:26:47 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <87d1c71468.fsf@jidanni.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="x27nBP17tC7XmXTOlnnaR3lp2i5eOd8BV" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Apr 2017 16:26:49 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --x27nBP17tC7XmXTOlnnaR3lp2i5eOd8BV Content-Type: multipart/mixed; boundary="EeR9jcGq6tuhKqtOghLWEILWicETBGIra"; protected-headers="v1" From: Eric Blake To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= Cc: 26576-done@debbugs.gnu.org Message-ID: Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> <87d1c71468.fsf@jidanni.org> In-Reply-To: <87d1c71468.fsf@jidanni.org> --EeR9jcGq6tuhKqtOghLWEILWicETBGIra Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 04/20/2017 10:37 AM, =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson wrote: > I want to do > $ cat file|some_program > but I must must exclude the UGLY line and its two neighbors. >=20 > OK I have found the UGLY line, and its two neighbors > $ grep -C 2 UGLY file > bla > bla > UGLY > bla > bla >=20 > but I have no way to exclude them before piping to some_program. So it sounds like you are asking for some sort of new --invert-output, which toggles which lines to display. Revisiting my example, it would change: $ seq 10 | grep -C 2 5 3 4 5 6 7 into: $ seq 10 | grep -C 2 5 --invert-output 1 2 -- 8 9 10 as well as: $ seq 10 | grep -C 2 -v 5 1 2 3 4 5 6 7 8 9 10 $ seq 10 | grep -C 2 -v '[3-8]' 1 2 3 4 -- 7 8 9 10 into: $ seq 10 | grep -C 2 -v 5 --invert-output $ seq 10 | grep -C 2 -v '[3-8]' --invert-output 5 6 It's very corner case, so I'm not sure it's worth burning an option and complicating grep to do this, plus waiting for a future version of grep with the proposed new option to percolate to your machines, when you already accomplish the same task using existing tools (admittedly with more complexity). For example, you can use sed twice if the data is in a file that can be re-read or easily regenerated (in this case, I'm skipping d, h, and any line within -C1 of the ugly lines): $ printf %s\\n a b c d e f g h i j > file $ ugly=3D$(sed -n '/[dh]/ =3D' file) $ sed "$(for line in $ugly; do echo "$((line-1)),$((line+1))d;"; done)" file a b f j Or it should be easy enough to write an awk script that stashes all input lines into one array, then checks for regular expression matches, and sets multiple entries in a corresponding poison array to 1 (based on how many lines of context you want to poison), then in an END block only print out lines if the corresponding poison[] entry is not 1. Although I'll leave that as an exercise for the reader. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --EeR9jcGq6tuhKqtOghLWEILWicETBGIra-- --x27nBP17tC7XmXTOlnnaR3lp2i5eOd8BV Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJY+OFHAAoJEKeha0olJ0NqoqAH+wclf/dwDlrOpyLFnY6sQifI nSratNeyoiSjBs5CU5eKVD1xwlGkd7eypmvfEnFX8xSlGaXdnbzQifYmUsBJs9J7 xNdTIc3bQCIViRv+Uz7rxE37lyhAW4aUxZRw2ksCViihtKTotwtDFxSl2x1X11R+ JBkYfbE66cPP1JpbH2tl/Ays+DHtycIeMH5HDjzpTMdpKyOU8ij/9HigEUUaJvXP ss0HRGfosu/U75i1jPgrqHRQ5yWSaPKyt6zpGn/iaxwwfcP2UHDKBLOC5gVrY6dd 1oU/xliOQnThf41f6ea4AfpTIiBWzX/lJUGv1i0FxPz/yQ7TxE5chyq1Usnr7Go= =vgaV -----END PGP SIGNATURE----- --x27nBP17tC7XmXTOlnnaR3lp2i5eOd8BV-- From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 12:38:13 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 16:38:13 +0000 Received: from localhost ([127.0.0.1]:59264 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1F5x-0002ov-4A for submit@debbugs.gnu.org; Thu, 20 Apr 2017 12:38:13 -0400 Received: from homie.mail.dreamhost.com ([208.97.132.208]:44226 helo=homiemail-a7.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1F5v-0002on-Kl for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 12:38:12 -0400 Received: from homiemail-a7.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a7.g.dreamhost.com (Postfix) with ESMTP id DFB6025C073; Thu, 20 Apr 2017 09:38:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to:cc :subject:references:date:message-id:mime-version:content-type; s=jidanni.org; bh=TxX6Eems5QyFnMXeClqosUnUWZQ=; b=etWwOw2iQczdZ jg5iyysfuEBnoef+1llkd7romsIHYmU29QBu7YtMl/dnktU1X+5GIxLT36BBMdmQ ACMRKwRYh3aT2m1PkcLB0G5nmx0Zx2XEaPCKhotAUZMoWK3/FZIR5hAROBaY7tPs /w1z96d/IO0urBvZVTW1xZwgiP7s5w= Received: from jidanni.org (111-246-102-19.dynamic-ip.hinet.net [111.246.102.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jidanni@jidanni.org) by homiemail-a7.g.dreamhost.com (Postfix) with ESMTPSA id 8F02225C062; Thu, 20 Apr 2017 09:38:09 -0700 (PDT) From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson To: Eric Blake Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> Date: Fri, 21 Apr 2017 00:38:04 +0800 Message-ID: <8760hz11cj.fsf@jidanni.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Yes, if somebody ever adds this option perhaps call it --compliment. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 12:48:40 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 16:48:40 +0000 Received: from localhost ([127.0.0.1]:59273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1FG4-00033a-DZ for submit@debbugs.gnu.org; Thu, 20 Apr 2017 12:48:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56236) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1FG3-00033N-4C for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 12:48:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 890EA8E682; Thu, 20 Apr 2017 16:48:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 890EA8E682 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 890EA8E682 Received: from [10.10.121.102] (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27AD880B23; Thu, 20 Apr 2017 16:48:33 +0000 (UTC) Subject: Re: bug#26576: -v when used with -C To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= References: <87o9vr16u7.fsf@jidanni.org> <8760hz11cj.fsf@jidanni.org> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: Date: Thu, 20 Apr 2017 11:48:27 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <8760hz11cj.fsf@jidanni.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="AV34VnXCP3qFHU3Pb3vHRs7RAAAiFi4eK" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Apr 2017 16:48:33 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --AV34VnXCP3qFHU3Pb3vHRs7RAAAiFi4eK Content-Type: multipart/mixed; boundary="vWh4iTJaclphCSahMxjAD76SEBmgqvaqQ"; protected-headers="v1" From: Eric Blake To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= Cc: 26576-done@debbugs.gnu.org Message-ID: Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> <8760hz11cj.fsf@jidanni.org> In-Reply-To: <8760hz11cj.fsf@jidanni.org> --vWh4iTJaclphCSahMxjAD76SEBmgqvaqQ Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 04/20/2017 11:38 AM, =E7=A9=8D=E4=B8=B9=E5=B0=BC Dan Jacobson wrote: > Yes, if somebody ever adds this option perhaps call it --compliment. Except that you mean --complement (you are not praising the lines, but making an opposite selection of lines). --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --vWh4iTJaclphCSahMxjAD76SEBmgqvaqQ-- --AV34VnXCP3qFHU3Pb3vHRs7RAAAiFi4eK Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJY+OZbAAoJEKeha0olJ0NqQNgIAIK1ArgIgBB8ILlFPdEUZzNK pif2qs9IehSO04nopWRCQQ8jq9fTNVAZpjm3FgON7NE9Z47xIhA361sEKUG66cjB gitgjQ/WOXAouEjMYFEyoSdcbzM2cqHl4r4ZBvu80dlchpGI3GPOBFIjJmjPsSAc QAMVbJHy2Yr5D7tJyobdjKTd7BbONTiZkzHtgLW1TIgsOAc8LoTck9OyvDc7xJhb n1Kv+nIygV4AYHtnp4Zz9gsXkE/VLDYa+Le2iHRXB9bXN/cDdJYNkZrF3b8UzqI9 m+Bkx5iA56YTNQqU2TJQeTFtxb4XBA9mzsYHv9gy2DDdBb7y15gDdjyoHVQuTHM= =kR0e -----END PGP SIGNATURE----- --AV34VnXCP3qFHU3Pb3vHRs7RAAAiFi4eK-- From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 12:52:04 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 16:52:04 +0000 Received: from localhost ([127.0.0.1]:59277 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1FJL-00038W-SO for submit@debbugs.gnu.org; Thu, 20 Apr 2017 12:52:04 -0400 Received: from mail-qt0-f169.google.com ([209.85.216.169]:33109) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1FJK-000382-BX for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 12:52:02 -0400 Received: by mail-qt0-f169.google.com with SMTP id m36so50188335qtb.0 for <26576-done@debbugs.gnu.org>; Thu, 20 Apr 2017 09:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=QzRY5bw4GJVi5P3Imj3hIv/SMQsLLDz7S4snjZuUSI8=; b=QaFMYPV0qpEVraLK+n2Y9/LjhHobgYdmHXa5xQ1n04pxQ/22I+4Mgt5bPj1VRhW5KK mp0l/5233RoMpbrvM0GoJznx38tR9a6AvP6dASdLYYoqGS/8T8EASLKeOKrtoVM1RVhY BK5bEDPyR4noeb08UZZD3h6PB6uE+B9spGDrZiBl8u2Fm7KIKedma6XPVJG/vaI78t47 Qe0VTF8z4wWG/ShBm7Zdg3Zi3LUXV9vMGtidZhziZevGI/BMfcHsr6FkFDrkveUBPx7H 9TOie+L/TGLE3ebIRxxaGzDVPhMVQbZhbGNl9S+NVZs1oFDCA03bWbKF0BYTZN9VZP6i JiHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=QzRY5bw4GJVi5P3Imj3hIv/SMQsLLDz7S4snjZuUSI8=; b=pnRbCo0isYizZTwzeHhvzq/XFEcAPf5IOa+pIxDs4Y6cUF5wQykQOqfviMQZfsM6Gr pfhoOMKzebohO+M1qcSN2gTTXO/NDC1tzas9M5G6jBI6LDBr97F39DO2pzn864wX1p3p vYqk/6SYEoSb1QygUY/1URjt8/vv/f/CWboMtYsSoN6r9t8G/xWb7SzGA82xa7hM3Rgh tAPFv9lbXceZWA1VxQdACn0POrflolZ81hE6QGe+JlYVtIsTcFrc77XmDCkrM77JuPzR Iy5chenGCKXYLMzmdSu1Wp3ICalgiTXg3U7X+5y3MJlylUbQ4/lPO3Lz8yc5aF86OXT+ tcoA== X-Gm-Message-State: AN3rC/5xGpL1QJPZ4fYClUARWrBaV2oFDvrHHy2mY+oXaA8xFefMvqS5 fwZxuA00hxvy/g== X-Received: by 10.200.40.72 with SMTP id 8mr8834815qtr.204.1492707116709; Thu, 20 Apr 2017 09:51:56 -0700 (PDT) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id m130sm4477956qke.66.2017.04.20.09.51.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Apr 2017 09:51:56 -0700 (PDT) Date: Thu, 20 Apr 2017 16:51:19 +0000 From: Assaf Gordon To: Eric Blake Subject: Re: bug#26576: -v when used with -C Message-ID: <20170420165118.GB11565@gmail.com> References: <87o9vr16u7.fsf@jidanni.org> <87d1c71468.fsf@jidanni.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org, =?utf-8?B?56mN5Li55bC8?= Dan Jacobson X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) Hello, On Thu, Apr 20, 2017 at 11:26:47AM -0500, Eric Blake wrote: >On 04/20/2017 10:37 AM, 積丹尼 Dan Jacobson wrote: >> I want to do >> $ cat file|some_program >> but I must must exclude the UGLY line and its two neighbors. >> >> OK I have found the UGLY line, and its two neighbors >> $ grep -C 2 UGLY file >> bla >> bla >> UGLY >> bla >> bla >> >> but I have no way to exclude them before piping to some_program. > >It's very corner case, so I'm not sure it's worth burning an option and >complicating grep to do this, plus waiting for a future version of grep >with the proposed new option to percolate to your machines, when you >already accomplish the same task using existing tools (admittedly with >more complexity). > If I may suggest the following sed program: $ cat file a b c bla1 bla2 UGLY bla3 bla4 e f g $ sed -n ':x 1,2{N;bx} ; /UGLY/{ N;N;z;bx }; /./P;N;D' file a b c e f g The combination of N/P/D commands use sed's pattern space as a fifo buffer (N appends a new line, P prints the last line, D deletes the last line). In between, if the pattern space contains the marker UGLY, the entire buffer is deleted and the cycle is restarted. Specifically: 1. ':x 1,2{N;bx}' => Load the buffer with the first two lines. 2. '/UGLY/ {N;N;z;bx}' => If the marker is found in the pattern space (which should contain 3 lines now), consume two more lines (N;N), clear the buffer (z) and jump to the beginning. 'z' is GNU extension. It can be replaced with 's/.*//'. 3. '/./P' => If the pattern space isn't empty, print up to the first line; 4. 'N;D' => Read the next line from the input file and append it to the pattern space, Delete the last line from the pattern space (the same line that was printed with 'P'). The following program can be used to learn a bit more about how the N/P/D commands work. It uses 'l' to the print content of the pattern space, and you can see it behaves like a FIFO: $ sed -n ':x 1,2{N;bx} ; l;P;N;D' file a\nb\nc$ a b\nc\nbla1$ b c\nbla1\nbla2$ c bla1\nbla2\nUGLY$ bla1 bla2\nUGLY\nbla3$ bla2 UGLY\nbla3\nbla4$ UGLY bla3\nbla4\ne$ bla3 bla4\ne\nf$ bla4 e\nf\ng$ e More information about sed's buffers can be found here: https://www.gnu.org/software/sed/manual/sed.html#advanced-sed hope this helps, regards, - assaf From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 13:05:56 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 17:05:56 +0000 Received: from localhost ([127.0.0.1]:59281 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1FWm-0003Ro-5l for submit@debbugs.gnu.org; Thu, 20 Apr 2017 13:05:56 -0400 Received: from homie.mail.dreamhost.com ([208.97.132.208]:51947 helo=homiemail-a7.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1FWl-0003Rh-Gu for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 13:05:55 -0400 Received: from homiemail-a7.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a7.g.dreamhost.com (Postfix) with ESMTP id ED80E25C06B; Thu, 20 Apr 2017 10:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to:cc :subject:references:date:message-id:mime-version:content-type: content-transfer-encoding; s=jidanni.org; bh=vxuN4GYedENe7EfDGnH R3D1HNok=; b=SSkUmstx2WshZo/e+JkIOBh1zACwZbxIKvh3n9yHq8wcL9SCSGC ILvC+z69z2gDWLmzguw7uWWlEAmBYGygWSzDF7kZqwLr7xEk97bNNLLeut+7vZ3z PlzVPIV5edU6L+xgtpuDXuqEm59ZrJBz+zHIOzKkyba0xTf1Q6A+Ghwo= Received: from jidanni.org (111-246-102-19.dynamic-ip.hinet.net [111.246.102.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: jidanni@jidanni.org) by homiemail-a7.g.dreamhost.com (Postfix) with ESMTPSA id 95EF425C06A; Thu, 20 Apr 2017 10:05:54 -0700 (PDT) From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson To: Assaf Gordon Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> Date: Fri, 21 Apr 2017 01:05:50 +0800 Message-ID: <871ssn1029.fsf@jidanni.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org, Eric Blake X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Yes those are brilliant uses of sed. However for now =E2=80=98-v=E2=80=99 =E2=80=98--invert-match=E2=80=99 Invert the sense of matching, to select non-matching lines. (=E2=80= =98-v=E2=80=99 is specified by POSIX.) perhaps should mention that "-v is processed before -C, -A, and -B, not a= fter." From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 20 15:34:58 2017 Received: (at 26576-done) by debbugs.gnu.org; 20 Apr 2017 19:34:58 +0000 Received: from localhost ([127.0.0.1]:59358 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Hqz-0006ys-VT for submit@debbugs.gnu.org; Thu, 20 Apr 2017 15:34:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56474) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1Hqx-0006yf-Nw for 26576-done@debbugs.gnu.org; Thu, 20 Apr 2017 15:34:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F0C19D51F; Thu, 20 Apr 2017 19:34:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7F0C19D51F Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7F0C19D51F Received: from [10.10.121.102] (ovpn-121-102.rdu2.redhat.com [10.10.121.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5C2217AF0; Thu, 20 Apr 2017 19:34:48 +0000 (UTC) Subject: Re: bug#26576: -v when used with -C To: Assaf Gordon References: <87o9vr16u7.fsf@jidanni.org> <87d1c71468.fsf@jidanni.org> <20170420165118.GB11565@gmail.com> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Organization: Red Hat, Inc. Message-ID: <6c0a3fc5-84c0-0845-f97e-37fff85526ed@redhat.com> Date: Thu, 20 Apr 2017 14:34:47 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: <20170420165118.GB11565@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1emJqUVddmi2mOsH1L3RISlOAQwX15xR0" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Apr 2017 19:34:49 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org, =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1emJqUVddmi2mOsH1L3RISlOAQwX15xR0 Content-Type: multipart/mixed; boundary="g02o15BVT5Pn9R62pjRv71oL9ICUGFjJQ"; protected-headers="v1" From: Eric Blake To: Assaf Gordon Cc: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= , 26576-done@debbugs.gnu.org Message-ID: <6c0a3fc5-84c0-0845-f97e-37fff85526ed@redhat.com> Subject: Re: bug#26576: -v when used with -C References: <87o9vr16u7.fsf@jidanni.org> <87d1c71468.fsf@jidanni.org> <20170420165118.GB11565@gmail.com> In-Reply-To: <20170420165118.GB11565@gmail.com> --g02o15BVT5Pn9R62pjRv71oL9ICUGFjJQ Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 04/20/2017 11:51 AM, Assaf Gordon wrote: > If I may suggest the following sed program: >=20 > $ cat file > a > b > c > bla1 > bla2 > UGLY > bla3 > bla4 > e > f > g >=20 > $ sed -n ':x 1,2{N;bx} ; /UGLY/{ N;N;z;bx }; /./P;N;D' file Works as long as lines 1 and 2 do not contain UGLY. But misbehaves if UGLY appears early: $ printf '2\nUGLY\n3\n4\nc\nd\n' | sed -n ':x 1,2{N;bx}; /UGLY/{N;N;z;bx}; /./P;N;D' d Oops - missed c. Also misbehaves if two occurrences of UGLY appear with overlapping contex= t: $ printf 'a\nb\n1\n2\nUGLY\n3\nUGLY\n4\n5\nc\nd\n' | sed -n ':x 1,2{N;bx}; /UGLY/{N;N;z;bx}; /./P;N;D' a b 4 5 c d Oops - didn't filter 4 and 5. May be fixable with even more magic, perhaps by using the hold buffer to track the status of the last three lines, and suppressing output if any of the last three inputs were UGLY. But more complicated than I want to spend time on for the sake of this email. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --g02o15BVT5Pn9R62pjRv71oL9ICUGFjJQ-- --1emJqUVddmi2mOsH1L3RISlOAQwX15xR0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJY+Q1XAAoJEKeha0olJ0NqAwkH/iMIIy1Qrl4SyFYZRE/LLcdh pdy2K7FWZ57HgCc+/HMYIPNQGvd9+Dqw+nk+WCHtHRH8sKoBb/4OoESGNjthhprM T5HT3Z9SrSnM6r70TOBYlbpOxlcGw9Qmst5Sq0iVjKWosh7cSkoCmyOxgP5kDdlv f29ylcQZFaMgbEG2lc5sbzZ+ZR2P2Rsg+14FmRIL+lydxs1yJuppTk4uYK4lAMXa tAos/8qTKGQlOB4063eYMTOnksrqRGIP1hM+Sohx92rRaRFpyfHKbH1T8UQ41V3t uzU9IF2s50JtV+FuDQvcpIXeTAAIi259Qv8RAdqLjbuN3t/BPtwPycXuegXK8Lk= =iv1r -----END PGP SIGNATURE----- --1emJqUVddmi2mOsH1L3RISlOAQwX15xR0-- From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 21 11:35:42 2017 Received: (at 26576-done) by debbugs.gnu.org; 21 Apr 2017 15:35:42 +0000 Received: from localhost ([127.0.0.1]:32786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1ab0-0003Dc-1e for submit@debbugs.gnu.org; Fri, 21 Apr 2017 11:35:42 -0400 Received: from mail-qk0-f174.google.com ([209.85.220.174]:36563) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1aay-0003DQ-HX for 26576-done@debbugs.gnu.org; Fri, 21 Apr 2017 11:35:40 -0400 Received: by mail-qk0-f174.google.com with SMTP id d80so9956672qke.3 for <26576-done@debbugs.gnu.org>; Fri, 21 Apr 2017 08:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=N6RpDuTyXHEjP61SVOu+3jIWszO3uOHho0mKsK+WnFM=; b=l3gsxyJ34rBwE+BJ/NSYCkKUNJ+ZgyP9AyGuOSTEDzvs5Ti4J1RsIJNand/hVVDeRb Gsdx/oOd7u9WI4le+5VIem51ZuiDNuxOGbxEfTldyNcVzWlMT8u6UPOxLJyTH4gRrhEi 2Ap65KodeQJMSlZH0V2fiT+jGfiYV/JWdXKbeFVIEsJuVywvW40ZdxKD+REZpEJVwPyw uRhbtlDP3uhRicr3ZOXASEOgHnWeQLNDGvMqavXwdthXlKUDYS1Bih6f3qkbi7sLKW1l u/zv7UFmHuvIFKwzabNb1b64QtOaYyKp3KlgFbMzrT/6/epxOKiwEvVG+vBv4th3ttrY rj3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=N6RpDuTyXHEjP61SVOu+3jIWszO3uOHho0mKsK+WnFM=; b=WZdKfCqBcqvouwy/OmspBkHBEevKjlLrgkKndfO2K4W11KMvYCIvx3UKdRuQpfZHXZ DOSTFX2VTiXfa8CVzuN0U3rcK04qlmg6ugAII8/0ZgbP5QWGJgCcEnK7Vp/noUIgxESB seEJH+yzheLGSjZfaCOmc56cuVJSdJVwKbVZXH19zsRcBXETkIVkHbbTQvT1gL8fk6Pd KuAGh1+jQaV2cIpjZa2teyXu0lvzBE1+3dOVKYcevvmGPQPZYizMQ1r0iihqxXCSWbHj adqpSgEm1kpl2dvLSiuZLu6cs9V8absTbiHh42xXQ0dX0phhRqUxIcyeO+2LUiNYaVbv rEdw== X-Gm-Message-State: AN3rC/7HFL7Py4NKdRWzYEltsfxSE5i6ZFGWUEvAhTJEgxcoq6fZw1Mi QVOLwxEAORNO1A== X-Received: by 10.55.86.70 with SMTP id k67mr13489898qkb.45.1492788935035; Fri, 21 Apr 2017 08:35:35 -0700 (PDT) Received: from gmail.com (housegordon.org. [104.236.108.240]) by smtp.gmail.com with ESMTPSA id t71sm6555163qki.8.2017.04.21.08.35.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Apr 2017 08:35:34 -0700 (PDT) Date: Fri, 21 Apr 2017 15:34:57 +0000 From: Assaf Gordon To: Eric Blake Subject: Re: bug#26576: -v when used with -C Message-ID: <20170421153456.GD11565@gmail.com> References: <87o9vr16u7.fsf@jidanni.org> <87d1c71468.fsf@jidanni.org> <20170420165118.GB11565@gmail.com> <6c0a3fc5-84c0-0845-f97e-37fff85526ed@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <6c0a3fc5-84c0-0845-f97e-37fff85526ed@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 26576-done Cc: 26576-done@debbugs.gnu.org, =?utf-8?B?56mN5Li55bC8?= Dan Jacobson X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) On Thu, Apr 20, 2017 at 02:34:47PM -0500, Eric Blake wrote: >On 04/20/2017 11:51 AM, Assaf Gordon wrote: > >> If I may suggest the following sed program: >> >> $ sed -n ':x 1,2{N;bx} ; /UGLY/{ N;N;z;bx }; /./P;N;D' file > >Works as long as lines 1 and 2 do not contain UGLY. But misbehaves if >UGLY appears early: [...] >Also misbehaves if two occurrences of UGLY appear with overlapping context: > [...] >May be fixable with even more magic, perhaps by using the hold buffer to >track the status of the last three lines, and suppressing output if any >of the last three inputs were UGLY. But more complicated than I want to >spend time on for the sake of this email. > Good catch, thanks for pointing this out. Indeed, that was an ad-hoc script, suitible for some limited scenarios but not robust as a general solution. -assaf From unknown Sun Jun 22 11:33:20 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 20 May 2017 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator