From unknown Fri Jun 20 07:20:05 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#47001 <47001@debbugs.gnu.org> To: bug#47001 <47001@debbugs.gnu.org> Subject: Status: Feature request: give a meaning to -A/-B/-C with -o Reply-To: bug#47001 <47001@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:20:05 +0000 retitle 47001 Feature request: give a meaning to -A/-B/-C with -o reassign 47001 grep submitter 47001 Gregory Heytings severity 47001 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 08 03:21:37 2021 Received: (at submit) by debbugs.gnu.org; 8 Mar 2021 08:21:37 +0000 Received: from localhost ([127.0.0.1]:42018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJB8z-0000Dq-55 for submit@debbugs.gnu.org; Mon, 08 Mar 2021 03:21:37 -0500 Received: from lists.gnu.org ([209.51.188.17]:47270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJB8v-0000Dg-Qg for submit@debbugs.gnu.org; Mon, 08 Mar 2021 03:21:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJB8v-00027M-Jk for bug-grep@gnu.org; Mon, 08 Mar 2021 03:21:33 -0500 Received: from heytings.org ([95.142.160.155]:51518) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJB8t-0006S2-ND for bug-grep@gnu.org; Mon, 08 Mar 2021 03:21:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20210101; t=1615191688; bh=NYsfpbjR40LySNuZ5tjzVmtlTmurvn0a9AU+BCr2JgE=; h=Date:From:To:Subject:Message-ID:From; b=NbFxe0CyaIE5gQLFpu6v2Wl5IU5o4aq0boBpDXTRoBd80U/0WNp2VlcQNxxzAlVJh Ipl2Qxrify7hxua60zLGYtVpwDYlTdYvtyKt1+WJ+NVbOOtQ0JN8Ys0dg9Sr924cUK F4I1ODSmiNAEexgf5VT446+izWavkmjKQWixNlASTQz0UbKdHlwWyRYQzOr6DhKXsB r0BSTlwZU9KkIWXIdibtvToiuuuwAxbXrvBNkwlZ/qnscA0Z8laCOVPSpAWpPgvYJf jYohDoI5XsVC4yLpiNv0iDhnroeS8Io0+1cAFus0OPfNWuH/llYfSiH/RaQrEy+dod rInnxUlwrHNsw== Date: Mon, 08 Mar 2021 08:21:27 +0000 From: Gregory Heytings To: bug-grep@gnu.org Subject: Feature request: give a meaning to -A/-B/-C with -o Message-ID: <3120d19b1db598625ddf@heytings.org> MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=us-ascii Received-SPF: pass client-ip=95.142.160.155; envelope-from=gregory@heytings.org; helo=heytings.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) 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: -2.3 (--) Hi list, Grep gives no meaning to the -A/-B/-C flags when they are used together with the -o flag (and prints a warning when they are used together). I suggest to give them a specific meaning when the -o flag is used, namely to print NUM _characters_ of trailing/leading/output context around the match. Currently this behavior can be obtained with "grep -oE '.{0,A}expose_frame.{0,B}'", where A and B are the number of leading and trailing context characters, but it is not efficient, and can become very inefficient for "large" values of A and B (say, 40). Thanks, Gregory From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 08 12:12:41 2021 Received: (at 47001) by debbugs.gnu.org; 8 Mar 2021 17:12:42 +0000 Received: from localhost ([127.0.0.1]:44643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJJQv-0001T9-Ny for submit@debbugs.gnu.org; Mon, 08 Mar 2021 12:12:41 -0500 Received: from heytings.org ([95.142.160.155]:48250) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJJQu-0001T1-7W for 47001@debbugs.gnu.org; Mon, 08 Mar 2021 12:12:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20210101; t=1615223558; bh=52MlK+bq1uiTUjv/aGyvYBI0pc3Rb8zOeO4ZnfNSq+g=; h=Date:From:To:Subject:In-Reply-To:Message-ID:References:From; b=kJJgPRJrlwL3X0h9Opdf3MAZsCXS20rAsucxDRJ5J1YuQSfucLmjHsCAaF9RI1Tou sJjGbnh3Q+Vw52+GRTdduyeBq8o5s29WO61phwJFJgRoYSDDNLuU++URP5Of9CthP8 qI0W2Z36t3W2N8kipj2AIsInjY914clS8xl8018BHhvbdoyeiqXujSYlugRJ6iLjzI OpiSHWt0byu9m0CoQeHozVNePEEjqKgpgcoEfq1u5301yro8iNQNPaI6Tezg8U/tU5 eNE1BV++NTKBD5F/Tajkddw/XN25zhSRQhGrl2QZyNZLO1lM3/SmxSvUO+jA1Th+a8 zjMinqEKs7tTQ== Date: Mon, 08 Mar 2021 17:12:38 +0000 From: Gregory Heytings To: 47001@debbugs.gnu.org Subject: Re: bug#47001: Feature request: give a meaning to -A/-B/-C with -o In-Reply-To: <3120d19b1db598625ddf@heytings.org> Message-ID: <3120d19b1de90830514f@heytings.org> References: <3120d19b1db598625ddf@heytings.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 47001 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: -1.0 (-) Two further comments: > > Grep gives no meaning to the -A/-B/-C flags when they are used together > with the -o flag (and prints a warning when they are used together). > Both the manual and the man page indicate that "a warning is given" when these options are used together, but what actually happens is that a group separator is printed at apparently random places. > > I suggest to give them a specific meaning when the -o flag is used, > namely to print NUM _characters_ of trailing/leading/output context > around the match. > > Currently this behavior can be obtained with "grep -oE > '.{0,A}expose_frame.{0,B}'", where A and B are the number of leading and > trailing context characters, but it is not efficient, and can become > very inefficient for "large" values of A and B (say, 40). > Of course I meant "grep -oE '.{0,A}PATTERN.{0,B}'. The "very inefficient" case happens in particular for very long lines: for i in $(seq 1 10) do printf %100000s | tr ' ' 'a' printf foobar printf %100000s | tr ' ' 'a' done | grep -oE '.{0,40}foobar.{0,40}'