From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 23 14:33:28 2024 Received: (at submit) by debbugs.gnu.org; 23 Apr 2024 18:33:30 +0000 Received: from localhost ([127.0.0.1]:53705 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzKxD-0000w6-Li for submit@debbugs.gnu.org; Tue, 23 Apr 2024 14:33:27 -0400 Received: from lists.gnu.org ([2001:470:142::17]:58268) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzKx3-0000oj-M5 for submit@debbugs.gnu.org; Tue, 23 Apr 2024 14:33:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzKwh-0007wR-26 for bug-grep@gnu.org; Tue, 23 Apr 2024 14:32:47 -0400 Received: from resdmta-a2p-641405.sys.comcast.net ([2001:558:fd01:2bb4::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzKwe-0006Di-GQ for bug-grep@gnu.org; Tue, 23 Apr 2024 14:32:46 -0400 Received: from resomta-a2p-647345.sys.comcast.net ([96.103.145.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resdmta-a2p-641405.sys.comcast.net with ESMTPS id zHLxrFRKLszgzzKwarTCqE; Tue, 23 Apr 2024 18:32:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20211018a; t=1713897160; bh=RPsOCgfR0RdjLbs8s0Cb4ZB9vtB1zF5x7h4wAFq7aew=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID:Xfinity-Spam-Result; b=VD1HrbCUYyhCT8NqKtHOPn9Ob4I693uPDv7XsXgsJUekvzknuNRaRGmDu7ZdCL8F9 idla2bcJU89vf/y31nQ0S0+Mo3t1HRysB1miCKRHSIxwXihYm//aMkOcfrEmhO/V7Q X/veIpOhHaaJOydYhw1dLC2/adTNf2Y+aSbc4AvdaSWMGW8bDnkjBQjUMiNzFLyYCz Xzju0+frkQAEW7mxsMsbuh+rM0ThtudPuRt2EPLimgOFe8d8lW4gio4+tJrF754pul i0GYIl8FZfNXHQuvGhhw7nPj15CnG9oYEzd7//xndFfZIwpd6069+d8koeRmtZ5Jsb ZdF0+0+PaPaLw== Received: from hobgoblin.ariadne.com ([IPv6:2601:192:4a00:430::508e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resomta-a2p-647345.sys.comcast.net with ESMTPSA id zKwYrfIbtjrQ5zKwZrk2z1; Tue, 23 Apr 2024 18:32:40 +0000 Received: from hobgoblin.ariadne.com (localhost [127.0.0.1]) by hobgoblin.ariadne.com (8.16.1/8.16.1) with ESMTPS id 43NIWcuS1213217 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Tue, 23 Apr 2024 14:32:38 -0400 Received: (from worley@localhost) by hobgoblin.ariadne.com (8.16.1/8.16.1/Submit) id 43NIWcXP1213214; Tue, 23 Apr 2024 14:32:38 -0400 X-Authentication-Warning: hobgoblin.ariadne.com: worley set sender to worley@alum.mit.edu using -f From: "Dale R. Worley" To: bug-grep@gnu.org Subject: grep -c -r | grep -v ':0$' Date: Tue, 23 Apr 2024 14:32:38 -0400 Message-ID: <87zftkx73t.fsf@hobgoblin.ariadne.com> X-CMAE-Envelope: MS4xfDLHrHLiJu8jq6xJn/WLA1DRaMfuzGKHpqmtFggU9VbgGV3jHfy6X96AYumTD8HvavtEeFhCUYv8c7MldiLm9mIC/lAnaAYNiMWvSmr3JsLQ1x1ZE8+d Pg6pZanyGnc6+mAX9il7H3qvjDLrVcpP/MrIDJ2fv2U8HOH1dWscehEN0T1APbgrTGtVjujVdEnHFuF0qGmCHbnf/xDL3gzsbtOw1sEA2f70I9c1J2o5gnOO Received-SPF: softfail client-ip=2001:558:fd01:2bb4::e; envelope-from=worley@alum.mit.edu; helo=resdmta-a2p-641405.sys.comcast.net X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.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: -0.0 (/) At least once a week, and often several times a day, I want to search a tree of files to list the files in a directory containing a pattern, along with the *numbers* of patterns in the files. Usually this is because I'm looking for a file that contains a number of instances of the pattern, from among which I will choose to copy something. But often the total number of files to be examined is large, and the total number of matches in any file might also be large. So "grep -r" is inconvenient, because it may return many more matches than I want to examine, and it can be hard to see what all the alternative files are among the large number of matches that can be returned from any one file. And "grep -c -r" is inconvenient, because it lists every file, even the large number containing no match. The idiom I usually use is "grep -c -r [pattern] [directory] | grep -v ':0$'", which lists the match counts, but only for files with non-zero counts. However, it seems "natural" to me that "grep -c -l", that is, "grep --count --files-with-matches", should give me this result. The current (ver. 3.6) behavior of grep is that combination acts like --files-with-matches alone. Looking at the comments in the grep code, it seems that Posix specifies that --count and --files-with-matches are incompatible, and thus this change would be upward-compatible with Posix. I've written a draft code revision, and it's simple, it doesn't require changes to the overall code structure. What do people think? Dale From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 24 08:56:44 2024 Received: (at submit) by debbugs.gnu.org; 24 Apr 2024 12:56:45 +0000 Received: from localhost ([127.0.0.1]:58321 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzcAz-00012P-SZ for submit@debbugs.gnu.org; Wed, 24 Apr 2024 08:56:44 -0400 Received: from lists.gnu.org ([2001:470:142::17]:50774) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzcAv-00010y-5E for submit@debbugs.gnu.org; Wed, 24 Apr 2024 08:56:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzcAR-00059G-EM for bug-grep@gnu.org; Wed, 24 Apr 2024 08:56:11 -0400 Received: from mail.oetec.com ([108.160.241.186]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzcAK-0007to-CK for bug-grep@gnu.org; Wed, 24 Apr 2024 08:56:06 -0400 Received: from [172.16.35.3] (pool-99-253-151-152.cpe.net.cable.rogers.com [99.253.151.152]) (authenticated bits=0) by mail.oetec.com (8.17.1/8.17.1) with ESMTPSA id 43OCtn8F007102 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 24 Apr 2024 08:55:50 -0400 (EDT) (envelope-from dclarke@blastwave.org) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=blastwave.org; s=default; t=1713963350; bh=2yooaC2u7nl8BrcFn8U85QPYghsDrfka/0cZIr3/R2Y=; h=Date:Subject:To:References:From:In-Reply-To; b=LasnAsI4hN/hopHl21DR3RRpz6ivqk0B9fD2p7EVwU8uZBbPGf4aWBve4Vix2iNfm uom7wIhGtdhLZMx53FgKK74zkTdTsGis3wSax3iGTY7LhGPbEeqg/GjNjmUYuNe1XH UL9hTFm3d9kxuSoO0nfHnbjCY1vzu1YlkJsqIekV7riYxgZ5cNWIyEF7Vn6TWKrjhv wmUyNrVF+X7ZTGt1vcIzIc9awUtEcpKOt+fyh8ezoRr+rxnElIHkeBa4fBx6/drqU6 /HVd2q29dnWZ/4WpmO0fGPuQePq+gc0n0xB/16jG4PWog1+yn6B5O4nIZz0TiIfT3Y HClDBIp+phZIg== Message-ID: Date: Wed, 24 Apr 2024 08:55:49 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#70540: grep -c -r | grep -v ':0$' Content-Language: en-CA To: bug-grep@gnu.org References: <87zftkx73t.fsf@hobgoblin.ariadne.com> From: Dennis Clarke Organization: GENUNIX In-Reply-To: <87zftkx73t.fsf@hobgoblin.ariadne.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-oetec-MailScanner-Information: Please contact the ISP for more information X-oetec-MailScanner-ID: 43OCtn8F007102 X-oetec-MailScanner: Found to be clean X-oetec-MailScanner-From: dclarke@blastwave.org X-Spam-Status: No Received-SPF: pass client-ip=108.160.241.186; envelope-from=dclarke@blastwave.org; helo=mail.oetec.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DEAR_SOMETHING=1.973, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.7 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: On 4/23/24 14:32, Dale R. Worley wrote: > At least once a week, and often several times a day ... Dear Sir : This is a task I can certainly relate to. Dragging through massive storage servers with find and grep is a terrible way to get things done. Content analysis details: (1.7 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.7 DEAR_SOMETHING BODY: Contains 'Dear (something)' 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) -0.0 SPF_HELO_PASS SPF: HELO matches SPF record 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: 0.7 (/) On 4/23/24 14:32, Dale R. Worley wrote: > At least once a week, and often several times a day ... Dear Sir : This is a task I can certainly relate to. Dragging through massive storage servers with find and grep is a terrible way to get things done. > I want to search a tree of files to list the files in a directory > containing a pattern ... That is usually the easy part of the problem. > along with the *numbers* of patterns in the files. That is not the easy part. > Usually this is because I'm looking for a file that contains a number > of instances of the pattern, from among which I will choose to copy > something. Perhaps a specific example would be helpful. Do you mean to say that you run "find" on a directory "./foo" and you search for all filenames that have a case sensitive pattern "BaR" in the filename? Then within the result set of filenames you count the instances of the string "BaR" inside the files that match? Are you only searching text files or will there be multi-lingual UTF-8 char encoded files? What about binary bit pattern match? > But often the total number of files to be examined is large, and the > total number of matches in any file might also be large. Here the word "large" can be tens of millions of files or perhaps even billions or trillions. Not sure what large means but certainly we are in the region of something possible with a decent modern server. > So "grep -r" is inconvenient, because it may return many more matches > than I want to examine, and it can be hard to see what all the > alternative files are among the large number of matches that can be > returned from any one file. > Without really understanding the problem you are trying to solve I have the sudden feeling what you really want is a custom written bit of code that walks down the directory structure and then does the read and inspection of each filename that matches some pattern. Making changes to grep for that purpose feels like making changes to a good working hammer in order to produce a chainsaw. However I am not sure what you mean by counting a "instances of the pattern". I have to guess that you want any filename with a pattern match AND twelve or fifty thousand instances of that pattern within the contents of the file. > > What do people think? > > Dale I think I want to setup an experiment and test this problem. -- Dennis Clarke RISC-V/SPARC/PPC/ARM/CISC UNIX and Linux spoken From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 24 16:27:36 2024 Received: (at 70540) by debbugs.gnu.org; 24 Apr 2024 20:27:37 +0000 Received: from localhost ([127.0.0.1]:60154 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzjDK-0005eA-66 for submit@debbugs.gnu.org; Wed, 24 Apr 2024 16:27:36 -0400 Received: from mail.cs.ucla.edu ([131.179.128.66]:35282) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzjDF-0005cY-VF for 70540@debbugs.gnu.org; Wed, 24 Apr 2024 16:27:32 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 288423C011BC5; Wed, 24 Apr 2024 13:27:06 -0700 (PDT) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id ne148QbBmKjC; Wed, 24 Apr 2024 13:27:05 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id CDA2A3C011BD4; Wed, 24 Apr 2024 13:27:05 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu CDA2A3C011BD4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1713990425; bh=v0+fksUbABMoAxjr8b8lAJboqdcUvuqNjhJ4yq8N9Vo=; h=Message-ID:Date:MIME-Version:To:From; b=gwgj8ivFm0RslWBfLYRVBIMuV/764leP1SHYM7DMjX7HFYBonryujjSGWRxb4Gw8F mDSCi98YXx+O/laJNVEdgmiddqlL8g5TPb3YqshA/uaibJPbVHM0XuWFnJ8kjvI9V1 nnkp8r7kkNFEoTMtj8l6L0DCMHE/zqC2g+WmfejGVrwceXdJwilVxQaVsmRZSgiFfS uoQaek1UJ8vFYaFkciDhsWIwlTqIMA0Y97hEYD4mhziPwyl9P9BMDJJeM8qRWmswE7 /lnZi10lHY5whHsbLbHNiE+gmelXcxZgL+498OcHI699KTwYXVtcQet5hhi6JVpYCl Gyt+g+tTrES+Q== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id 6P4hp9x2XU8R; Wed, 24 Apr 2024 13:27:05 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id B6A2D3C011BC5; Wed, 24 Apr 2024 13:27:05 -0700 (PDT) Message-ID: <6cc34f52-2d3b-40bd-a293-d33366eec3c9@cs.ucla.edu> Date: Wed, 24 Apr 2024 13:27:05 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#70540: grep -c -r | grep -v ':0$' To: "Dale R. Worley" References: <87zftkx73t.fsf@hobgoblin.ariadne.com> Content-Language: en-US From: Paul Eggert Autocrypt: addr=eggert@cs.ucla.edu; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiH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73Md59K7PuEKN1NxzlWiqqQHZZ9momN0GXLPcGq 4uyfq7yVEy7wP5PMOh6oqscKklE3gFQtq0P1Ki0xqdF6Fq5LPJc+0Db2CYkVIy7Xaa/f74I3 sOfQfEeDylVXR5iDfUJEYv/0DYhOr7q5/0b1kh3M4wkrB4C5jVNHjIIj+RsAK90c3t38OhAl jiSN7Bkwy24Afy8eIu6wWzvhnsQGpZPB+IffmxT1wkTy8UxZKjUWV0C82iphVgCUUi2f9sDV Q/tNcwVWmOS+gdv9Wk6tdGeM+Ee+Qs6YG05jcSoajzF0TL07ajLcayRq2j1Os2CtQ8qu Organization: UCLA Computer Science Department In-Reply-To: <87zftkx73t.fsf@hobgoblin.ariadne.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 70540 Cc: 70540@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: -1.0 (-) On 4/23/24 11:32 AM, Dale R. Worley wrote: > However, it seems "natural" to me that "grep -c -l", that is, "grep > --count --files-with-matches", should give me this result. Yes, that sounds reasonable. Is your patch a trivial one (10 lines or less)? If so, please send it in. If not, please send in copyright paperwork for grep (I can send you the form for that). Thanks. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 25 16:10:58 2024 Received: (at 70540) by debbugs.gnu.org; 25 Apr 2024 20:10:58 +0000 Received: from localhost ([127.0.0.1]:33298 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s05Qm-00030L-ML for submit@debbugs.gnu.org; Thu, 25 Apr 2024 16:10:57 -0400 Received: from resqmta-h2p-567038.sys.comcast.net ([2001:558:fd02:2446::7]:25040) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s05Qi-0002z3-BO for 70540@debbugs.gnu.org; Thu, 25 Apr 2024 16:10:54 -0400 Received: from resomta-h2p-555060.sys.comcast.net ([96.102.179.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resqmta-h2p-567038.sys.comcast.net with ESMTPS id zzULrsdBc3eYF05QJs4y13; Thu, 25 Apr 2024 20:10:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20211018a; t=1714075827; bh=khCsRzKsuL+ccB4Y4o7XK4cD/Fm+zdA37+NRcDX+pTU=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID:Xfinity-Spam-Result; b=JYZ1+O2p1TP9IN8GE/KhFNrpZ1m8i0KZ30ykXh6PNl155HUEX5Q3/UFceRyvTe2WS lxfIMvRM1E9VVO2KS+1iF6CuxLmGLBVq/cziV6vd633iue5+Q6XCotukFfFRFZY07E kCFQWsFlYb5YNLqWcYkaEpZtDRxabkTzBw8y5lJO6xS+fZAUI3veAkYL4Wz0nWuEkD FVRV7Wd2CMrJsXer9+kVPbXOmIisAPgXtSePEwCimlxV6SoHjIj38jXjTPYoEQ2Gkh 57AzNA6ManrOT+93CIti2zZmGYHB3NSZ/A0ixIR1Qsy2BxuApWzitXSljk63xcNkWg W1wotA6X9/WJw== Received: from hobgoblin.ariadne.com ([IPv6:2601:192:4a00:430::508e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resomta-h2p-555060.sys.comcast.net with ESMTPSA id 05QGsvZ0gFRwk05QHsdnB9; Thu, 25 Apr 2024 20:10:27 +0000 Received: from hobgoblin.ariadne.com (localhost [127.0.0.1]) by hobgoblin.ariadne.com (8.16.1/8.16.1) with ESMTPS id 43PKAN3r1498170 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 25 Apr 2024 16:10:23 -0400 Received: (from worley@localhost) by hobgoblin.ariadne.com (8.16.1/8.16.1/Submit) id 43PKANhp1498166; Thu, 25 Apr 2024 16:10:23 -0400 X-Authentication-Warning: hobgoblin.ariadne.com: worley set sender to worley@alum.mit.edu using -f From: "Dale R. Worley" To: Paul Eggert Subject: Re: bug#70540: grep -c -r | grep -v ':0$' In-Reply-To: <6cc34f52-2d3b-40bd-a293-d33366eec3c9@cs.ucla.edu> (eggert@cs.ucla.edu) Date: Thu, 25 Apr 2024 16:10:23 -0400 Message-ID: <87frv9w6ds.fsf@hobgoblin.ariadne.com> X-CMAE-Envelope: MS4xfAETTYDvqmWJu2G3wxcD4qWunMKcbfChZV2ufYgLdGkL4My1KVDCmkhL9gE4b3XdEIYd/0yeiuv3FpqlCsAY+HjvJZIVcCzO4vlXUd9Wn70NTAd+lH/E ByTYZx+p8DGiRTjHsJ4YS04zXWtk7Sy1CwsZ9koSHVYZ39c8AN6q8JfQ+M3ziOwrJWFGFEcycahHEOdl2t8UXibm2cHWBpftLELTo0BXM0at4HpG9zGmLGnU 2x93i28rCT22hm6BSMAZ4g== X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 70540 Cc: 70540@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.7 (/) Paul Eggert writes: > On 4/23/24 11:32 AM, Dale R. Worley wrote: >> However, it seems "natural" to me that "grep -c -l", that is, "grep >> --count --files-with-matches", should give me this result. > > Yes, that sounds reasonable. Is your patch a trivial one (10 lines or > less)? If so, please send it in. If not, please send in copyright > paperwork for grep (I can send you the form for that). Thanks. The functional code is a bit less than 10 lines, but adding in comments and updates to the tests it's significantly longer. So send me the form. One further thing, I haven't written any updates to the manual page or .texi. Does anyone have suggestions for a good way to do that? Also, the code change does *not* implement --count --files-without-match. In a sense, that ought to become defined also, but the output would be the same as for --files-without-match with each file name getting ":0" appended, which seems not worth the trouble of implementing. Dale From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 25 16:30:44 2024 Received: (at 70540) by debbugs.gnu.org; 25 Apr 2024 20:30:45 +0000 Received: from localhost ([127.0.0.1]:33303 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s05jp-0006Xy-Mc for submit@debbugs.gnu.org; Thu, 25 Apr 2024 16:30:43 -0400 Received: from resqmta-c2p-570503.sys.comcast.net ([2001:558:fd00:56::5]:58738) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s05ji-0006Vf-8S for 70540@debbugs.gnu.org; Thu, 25 Apr 2024 16:30:34 -0400 Received: from resomta-c2p-555661.sys.comcast.net ([96.102.18.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resqmta-c2p-570503.sys.comcast.net with ESMTPS id 0383sSSFLbwk305jJsOYv8; Thu, 25 Apr 2024 20:30:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20211018a; t=1714077005; bh=zFACLm3Gj+NcAbyovCaRQcIv/ZPko7DIeibKiXKuK08=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID:Xfinity-Spam-Result; b=t/owYrlikSI6FEoa6RTJRwOLn769OkaqGy9fnlTvfc4bPJFVWg3kvC8u+0kYcAxk/ LLFUOJ6/aNfIxDf8u6gXBgRwnMUXwtZh9ie2g2yAqRpalOsiX9ip2BEFNkC8DgJzdb mq4eNVuXTVsJlIoDY6YH6a5+wX6a2gl6meOuHeb51qhnXciLALkpHvLEq/aq1593j9 feIWxLXI7d+wbBmgR5xmG5sCUcPuC+Zb2NOlsy4O8au88NQKIesR7veB1FqeEBSrI4 lgcyLZ+yix5JsQSRXcB7jFU6EaolvxiHT4gUMbM45uMlu6PHYmcHImw+Vz8nqNSMoW D4QpFsFPEHmnw== Received: from hobgoblin.ariadne.com ([IPv6:2601:192:4a00:430::508e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resomta-c2p-555661.sys.comcast.net with ESMTPSA id 05jGsnph8Oz9C05jHsQSSy; Thu, 25 Apr 2024 20:30:04 +0000 Received: from hobgoblin.ariadne.com (localhost [127.0.0.1]) by hobgoblin.ariadne.com (8.16.1/8.16.1) with ESMTPS id 43PKU2LB1504753 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 25 Apr 2024 16:30:02 -0400 Received: (from worley@localhost) by hobgoblin.ariadne.com (8.16.1/8.16.1/Submit) id 43PKU10q1504665; Thu, 25 Apr 2024 16:30:01 -0400 X-Authentication-Warning: hobgoblin.ariadne.com: worley set sender to worley@alum.mit.edu using -f From: "Dale R. Worley" To: Dennis Clarke Subject: Re: bug#70540: grep -c -r | grep -v ':0$' In-Reply-To: (bug-grep@gnu.org) Date: Thu, 25 Apr 2024 16:30:01 -0400 Message-ID: <87a5lhw5h2.fsf@hobgoblin.ariadne.com> X-CMAE-Envelope: MS4xfOnJmKXOfesR7K6c47S0U5DCCiaRYvHMGbHKqi+/yHEnudMz6UbhJT6mQf7vytPzaF7EErQkBkGkOESL90FR8GmGDtGN1vWCnsKV5C6JfJ6uGaxs+Nhg HTiNJY+Dmn5Yw7nH18YFxkvN6PbgCWtVvT7ZWhF6uZ0diNJyPr1JnIEbFsfYlJIpZe/G7x+sBqTjnzE3y0CcmuLcOcLqthCN4smp5ic4vzYIjlFiySawH7So ktPlm6iB49OstQxbxGyVr0dGiY9/Y2EdokSuEgVqsKs= X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 70540 Cc: 70540@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 (/) Dennis Clarke via Bug reports for GNU grep writes: > Perhaps a specific example would be helpful. My most common case is something like grep -c --files-with-match 'some fragment of a command' ~/temp/shell.10?? which is searching the log files of my old shell sessions to find the most recent session that has "many" uses of "some fragment of a command". Often, because I want to copy-modify-paste that command to use in a current shell session. Conceptually, the search process is: find all files that mention the command, sort them by number of uses of the command, then look at the contents of the one or two files with the *most* uses (because there often are accidental matches in session logs that don't "really" use the command). Given that my desired command is unlikely to output more than 5 or so lines, this patch makes that process straightforward. Another case is grep -c --files-with-match variable_name ~/bash-5.5.17 where I want to first look into the files that most often mention variable_name to see exactly how it is used. If these weren't ad-hoc activities, I would construct a careful pipeline like grep -c -r pattern directory | sort -t: -k2,2r | head -n3 but for ad-hoc use, it seems to me that it's sensible and convenient to make the combination -c -l do what it intuitively "ought" to do, given that that change would be upward-compatible with Posix. Dale From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 25 16:54:58 2024 Received: (at 70540) by debbugs.gnu.org; 25 Apr 2024 20:54:58 +0000 Received: from localhost ([127.0.0.1]:33308 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s067M-0002hy-1a for submit@debbugs.gnu.org; Thu, 25 Apr 2024 16:54:57 -0400 Received: from mail.cs.ucla.edu ([131.179.128.66]:45914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s067I-0002fo-9W for 70540@debbugs.gnu.org; Thu, 25 Apr 2024 16:54:54 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 2BE2C3C013279; Thu, 25 Apr 2024 13:54:28 -0700 (PDT) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id 00NMtHkW3RSk; Thu, 25 Apr 2024 13:54:27 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id B02763C00FAB4; Thu, 25 Apr 2024 13:54:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu B02763C00FAB4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1714078467; bh=whOAe/56L+XA2Pg9p5aNA4pjfPzKlI+3XmcLvAZJJmE=; h=Message-ID:Date:MIME-Version:To:From; b=R6cpil/+SbwskR5HcAK3of7XX0YbysP1fMIuCrG0OKEODgPD5k4fOF+C5IlLo9qjt bTr/AXIUECdTeN/NeV8kjFsmhM9r0fowjCQ7R9IIE7TXrBWokOnwbcQpafiq0Mkhta dxEsEQuiEe1aNrPZc4W989sgL0X6XIWtABrOuD5gKQxYaQWecc9XNDB/v/EVh56NL6 KFJwvZ9YmgwKoOEUKCpYEU65uWKEp4j1fhHPGGkVU3XlTh0PToPR7bjqcSe2Mpl3gI MeOaNJ8IHV+mChVva5iD/up9+u8a4lrH4Mr2clA73mMJL8vAdKKYmFM3qpqv2CrZMR 9Dq8l/C2vapfg== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id SB8kon5XC0CL; Thu, 25 Apr 2024 13:54:27 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id 98D963C013279; Thu, 25 Apr 2024 13:54:27 -0700 (PDT) Message-ID: <0b8aade3-5712-4b19-a2fa-5597eca9d606@cs.ucla.edu> Date: Thu, 25 Apr 2024 13:54:27 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#70540: grep -c -r | grep -v ':0$' To: "Dale R. Worley" References: <87frv9w6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I+uYkRxUFp92ykmdhDEFg1yjYsU8iGU69a Hyvhq36z4zctvbqhRNzOWB1bVJ/dIMDvsExGcXQVDIT7sDNXv0wE3jKSKpp7NDG1oXUXL+2+ SF99Kjy753AbQSAmH617fyBNwhJWvQYg+mUvPpiGOtses9EXUI3lS4v0MEaPG43flEs1UR+1 rpFQWVHo1y1OO+sAEQEAAcLBfAQYAQgAJgIbDBYhBH43kqnYrPfWM7wViO2X6Q5iqn40BQJm Is58BQkdZAsMAAoJEO2X6Q5iqn40Q68QAJ9GubS/ej30Vc4idoZdc0IyMcL7kQJbMohF+Tyn ZE+TGn9WvzP10yLyzoI0vNlcNfP92d2MS//pFjOuANb5mwyiEYA+rDZIdS4ZZpHxCs2sxMC4 afLCf3kv4aMnTeBvb9na403dlczz9cAacvsmniSFdpb1+BzMpYbybglU5oYMGhYT2nnCRjXN 6S2nKYt4mjJeeOuxHrdeqQQdVBNYeNfTcPePeqvZ2+bD6u9yxZtaV+wxdpqglosQvjqhOYz7 h50/ZTSq70/npoCq44TzdJKttaYvlW6ziRz0g4RRAqZyoxjYXiy5qj8r8zXJuB11ApZCGuKn /usbji9RYbflAhxFeh4LMmpDVi6BrF30b73Md59K7PuEKN1NxzlWiqqQHZZ9momN0GXLPcGq 4uyfq7yVEy7wP5PMOh6oqscKklE3gFQtq0P1Ki0xqdF6Fq5LPJc+0Db2CYkVIy7Xaa/f74I3 sOfQfEeDylVXR5iDfUJEYv/0DYhOr7q5/0b1kh3M4wkrB4C5jVNHjIIj+RsAK90c3t38OhAl jiSN7Bkwy24Afy8eIu6wWzvhnsQGpZPB+IffmxT1wkTy8UxZKjUWV0C82iphVgCUUi2f9sDV Q/tNcwVWmOS+gdv9Wk6tdGeM+Ee+Qs6YG05jcSoajzF0TL07ajLcayRq2j1Os2CtQ8qu Organization: UCLA Computer Science Department In-Reply-To: <87frv9w6ds.fsf@hobgoblin.ariadne.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 70540 Cc: 70540@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: -1.0 (-) On 4/25/24 13:10, Dale R. Worley wrote: > One further thing, I haven't written any updates to the manual page or > .texi. Does anyone have suggestions for a good way to do that? If you have time, just edit those two files and include the edits as part of your patch. If not, I can write that part. > Also, the code change does *not* implement --count > --files-without-match. Makes sense to me. From debbugs-submit-bounces@debbugs.gnu.org Thu Apr 25 17:49:46 2024 Received: (at 70540) by debbugs.gnu.org; 25 Apr 2024 21:49:47 +0000 Received: from localhost ([127.0.0.1]:33343 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s06yN-0004VU-UU for submit@debbugs.gnu.org; Thu, 25 Apr 2024 17:49:46 -0400 Received: from wfhigh8-smtp.messagingengine.com ([64.147.123.159]:50701) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s06yK-0004TR-AN for 70540@debbugs.gnu.org; Thu, 25 Apr 2024 17:49:42 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 1C0B3180011A; Thu, 25 Apr 2024 17:49:16 -0400 (EDT) Received: from imap53 ([10.202.2.103]) by compute2.internal (MEProxy); Thu, 25 Apr 2024 17:49:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1714081755; x=1714168155; bh=JuIcGgdzNO Qty4ItHVt0caHGQ1DE9IfFxAq21LKLnVU=; b=po8KarFeZF0UDa0jId9e/ExEfv EQr9sk+tLlyJHLv3XZFWdq7PVQk+5XjlItDVdPFwGj+aK+0N04tjbA+aavxLH/7H fq8Ve8oWrYAuwVu/edsmzELXFsTv2iNNojukqJzJb7rPsRRPSufscgUFH5ch2IMB RAdUJWqtAEFQWDo1Git4X7p8sckAEeCYOP2r/BvMojMFqwAnqtbWj8NOBGBkDdjF ZHmkuq9pnk1rpIPxNbGEApOMNnZzzsw4EuH6wt+WeeJ5O/FhzkTSGO1Ez4+GizGU YvUXkngrVXSGVu7nAzz7uVZyK6VYhdyDcf9+QxBM+gjsm4FwC9iOq8WZlnOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1714081755; x=1714168155; bh=JuIcGgdzNOQty4ItHVt0caHGQ1DE 9IfFxAq21LKLnVU=; b=a0AUW31z4zjewavcU8v95aPGE1142dB0LddHV6NiscBO wUqnVmmSUrP1AukdZwqsWWNVi6cw2PNVPgJjbGoZKuUwAWNnNfQL3Hs9zNpSQdHS Y3QlpDQ7hlYTCMVY5X7aARSMfx4fvXR5ad11WhftUga1V4J8xMnkNdjqNGv7bGHR /+dqB+z/z6PG7j2/2twxZVTSOTeVd+IUyE0qtjVbHMVNBJOd6dmPRxu5XtM5N1bm 6pKQBBqnQgTbDRoS7HT0DTxZNN/yBJ/GCSjgcLdDaSU7ylTQlutMbsnbfiGon+jm oyAybUYjoYhT+ro6qt59D7AFnGnBeJYBVHKctFkUNQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudelkecutefuodetggdotefrodftvfcurf hrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefofgggkfgjfhffhffvvefutgesrgdtreerreertdenucfhrhhomhepjhgrtghkshho nhesfhgrshhtmhgrihhlrdgtohhmnecuggftrfgrthhtvghrnhepueduteduhfekffelje evteevgeduhffgudeftefftedvteevtdelieduveetkedunecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhgrtghkshhonhesfhgrshhtmhgrih hlrdgtohhm X-ME-Proxy: Feedback-ID: i982440cf:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3238F364006F; Thu, 25 Apr 2024 17:49:15 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-386-g4cb8e397f9-fm-20240415.001-g4cb8e397 MIME-Version: 1.0 Message-Id: In-Reply-To: <0b8aade3-5712-4b19-a2fa-5597eca9d606@cs.ucla.edu> References: <87frv9w6ds.fsf@hobgoblin.ariadne.com> <0b8aade3-5712-4b19-a2fa-5597eca9d606@cs.ucla.edu> Date: Thu, 25 Apr 2024 16:48:20 -0500 From: jackson@fastmail.com To: "Paul Eggert" , "Dale R. Worley" Subject: Re: bug#70540: grep -c -r | grep -v ':0$' Content-Type: multipart/alternative; boundary=98516fa795a5482cb4d9b41f37b38eb7 X-Spam-Score: 0.3 (/) X-Debbugs-Envelope-To: 70540 Cc: 70540@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: -1.7 (-) --98516fa795a5482cb4d9b41f37b38eb7 Content-Type: text/plain Dale wrote: > If these weren't ad-hoc activities, I would construct a careful pipeline > like > > grep -c -r pattern directory | sort -t: -k2,2r | head -n3 > > but for ad-hoc use, it seems to me that it's sensible and convenient to > make the combination -c -l do what it intuitively "ought" to do, given > that that change would be upward-compatible with Posix. When I have frequently used cases like that, and get tired of just typing it all into a shell prompt over and over, I write a little wrapper command (perhaps in C, shell, Python or some combination) that encapsulates the repetitively useful details. My personal src and bin directories have hundreds of such commands, some dating as far back as early 1980's when I was at Bell Labs. (Though this habit can become annoying when I am on someone else's computer, and half the command lines I type at a shell prompt fail "command not found".) -- Paul Jackson jackson@fastmail.fm --98516fa795a5482cb4d9b41f37b38eb7 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
Dale wrote:
If these weren't ad-hoc activities, I would constru= ct a careful pipeline
like

    grep -c -r pattern directory | sort -t: = -k2,2r | head -n3

<= div style=3D"font-family:Arial;">but for ad-hoc use, it seems to me that= it's sensible and convenient to
make the combination -c -l do what it intuitively "ought" to do, giv= en
that that change would be = upward-compatible with Posix.

When I have fr= equently used cases like that, and get tired of just typing it all into = a shell prompt over and over, I write a little wrapper command (perhaps = in C, shell, Python or some combination) that encapsulates the repetitiv= ely useful details.  My personal src and bin directories have hundr= eds of such commands, some dating as far back as early 1980's when I was= at Bell Labs.  (Though this habit can become annoying when I am on= someone else's computer, and half the command lines I type at a shell p= rompt fail "command not found".)

-- 
Paul Jackson
--98516fa795a5482cb4d9b41f37b38eb7-- From debbugs-submit-bounces@debbugs.gnu.org Sun Apr 28 18:45:38 2024 Received: (at 70540) by debbugs.gnu.org; 28 Apr 2024 22:45:38 +0000 Received: from localhost ([127.0.0.1]:53305 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s1DH7-0005qw-A3 for submit@debbugs.gnu.org; Sun, 28 Apr 2024 18:45:37 -0400 Received: from resdmta-c2p-566137.sys.comcast.net ([2001:558:fd00:56::c]:50164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s1DH4-0005qp-QG for 70540@debbugs.gnu.org; Sun, 28 Apr 2024 18:45:36 -0400 Received: from resomta-c2p-539727.sys.comcast.net ([96.102.18.242]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resdmta-c2p-566137.sys.comcast.net with ESMTPS id 1DBysqwnDPiKq1DGesMfEi; Sun, 28 Apr 2024 22:45:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcastmailservice.net; s=20211018a; t=1714344308; bh=a2/UNO4ec2E5w2MDYozwRuvS/AQ2F5CISwbqZy8xI6s=; h=Received:Received:Received:Received:From:To:Subject:Date: Message-ID:Xfinity-Spam-Result; b=p4BRfIoSadTfVnVG+QSo5fnM5f4MgNfmyNb2KltXSXYEL3orKoTBT61QOYQV7qy2J 30E3TdkRJRia9tcVfB+j8Dwc4YRDsYBmxcC/el/OVgwlUYCDBcaO2HWWh1Bjm7pF9X Cts+e1HueuTBN9PZkhj5PztSKIqnkkIpqE7Rv/4DbqCwzrBGrqs7+44XYt/5/LOe6n roted8VM3RwuIl6pSye0oWS7bCL8agvaYb4xVoMKPauqg18LsOCvgkT+0RoUukcyDO viYwwGkMyB0XA/9zeR486VyPvyOXvTdOtb2x1loFJoNwtqXvAsNXLBiAuSHiqpW9z7 tAOAn04BgGwXw== Received: from hobgoblin.ariadne.com ([IPv6:2601:192:4a00:430::10f6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by resomta-c2p-539727.sys.comcast.net with ESMTPSA id 1DGIsrqz9HFjr1DGJsWRrm; Sun, 28 Apr 2024 22:44:47 +0000 Received: from hobgoblin.ariadne.com (localhost [127.0.0.1]) by hobgoblin.ariadne.com (8.16.1/8.16.1) with ESMTPS id 43SMijR32038453 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 28 Apr 2024 18:44:46 -0400 Received: (from worley@localhost) by hobgoblin.ariadne.com (8.16.1/8.16.1/Submit) id 43SMijlD2038450; Sun, 28 Apr 2024 18:44:45 -0400 X-Authentication-Warning: hobgoblin.ariadne.com: worley set sender to worley@alum.mit.edu using -f From: "Dale R. Worley" To: Paul Eggert Subject: Re: bug#70540: grep -c -r | grep -v ':0$' In-Reply-To: <0b8aade3-5712-4b19-a2fa-5597eca9d606@cs.ucla.edu> (eggert@cs.ucla.edu) Date: Sun, 28 Apr 2024 18:44:45 -0400 Message-ID: <87h6fl85uq.fsf@hobgoblin.ariadne.com> X-CMAE-Envelope: MS4xfJCxrQEg1RthW+HUGtrC8PywWYlUFUV1B/jFwDna2ymXK7ZkJTSxcDX0ihhcSQixUFGis/Zq0tef9k3ytAIO7/Cn8yZB5KI3EmvuNSOS7fI7BoSuVDjk +l9/FJox6hCeZYxZOC668CwmJwVYDkS52rspHPrjUpgZh9gJJbuJQ/RLq2e/r2XQit0KeNMxyiYzUcse3Rx/N0o4PM3kEcgwW3ZooXADPy+o3ViXV/H4MWTA Aoyes12PBlG7LeykoYRmRA== X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 70540 Cc: 70540@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 (/) For everyone's critique, here are my changes (to grep 3.11): diff -u doc/grep.in.1.orig doc/grep.in.1 --- doc/grep.in.1.orig 2024-04-28 18:04:37.494096472 -0400 +++ doc/grep.in.1 2024-04-28 18:24:15.187984393 -0400 @@ -2,7 +2,7 @@ .de dT .ds Dt \\$2 .. -.dT Time-stamp: "2019-12-29" +.dT Time-stamp: "2024-04-28" .\" Update the above date whenever a change to either this file or .\" grep.c's 'usage' function results in a nontrivial change to the man page. .\" In Emacs, you can update the date by running 'M-x time-stamp' @@ -292,6 +292,9 @@ With the .BR \-v ", " \-\^\-invert\-match option (see above), count non-matching lines. +With the +.BR \-l ", " \-\^\-files\-with\-matches +option (see below), only files with non-zero counts are listed. .TP .BR \-\^\-color [ =\fIWHEN\fP "], " \-\^\-colour [ =\fIWHEN\fP ] Surround the matched (non-empty) strings, matching lines, context lines, diff -u doc/grep.texi.orig doc/grep.texi --- doc/grep.texi.orig 2024-04-28 18:04:40.302091195 -0400 +++ doc/grep.texi 2024-04-28 18:17:22.567712036 -0400 @@ -301,6 +301,10 @@ With the @option{-v} (@option{--invert-match}) option, count non-matching lines. (@option{-c} is specified by POSIX.) +With the @option{-l} (@option{--files-with-matches}) option, +only files with non-zero counts are listed. +(The combination of @option{-c} and @option{-l} is not specified by +POSIX.) @item --color[=@var{WHEN}] @itemx --colour[=@var{WHEN}] diff -u src/grep.c.orig src/grep.c --- src/grep.c.orig 2023-04-10 20:20:47.000000000 -0400 +++ src/grep.c 2024-04-28 17:57:22.527913936 -0400 @@ -1084,6 +1084,8 @@ static intmax_t out_before; /* Lines of leading context. */ static intmax_t out_after; /* Lines of trailing context. */ static bool count_matches; /* Count matching lines. */ +static bool count_matches_nonzero; /* Count matching lines; only + report files with matches. */ static intmax_t max_count; /* Max number of selected lines from an input file. */ static bool line_buffered; /* Use line buffering. */ @@ -1914,17 +1916,20 @@ count = grep (desc, &st, &ineof); if (count_matches) { - if (out_file) - { - print_filename (); - if (filename_mask) - print_sep (SEP_CHAR_SELECTED); - else - putchar_errno (0); - } - printf_errno ("%" PRIdMAX "\n", count); - if (line_buffered) - fflush_errno (); + if (!(count_matches_nonzero && count == 0)) + { + if (out_file) + { + print_filename (); + if (filename_mask) + print_sep (SEP_CHAR_SELECTED); + else + putchar_errno (0); + } + printf_errno ("%" PRIdMAX "\n", count); + if (line_buffered) + fflush_errno (); + } } status = !count; @@ -2891,9 +2896,16 @@ } /* POSIX says -c, -l and -q are mutually exclusive. In this - implementation, -q overrides -l and -L, which in turn override -c. */ + implementation, -q overrides -l and -L. -L in turn overrides -c, + but -l is compatible with -c because this implementation uses + that combination to specify listing only non-zero counts. */ if (exit_on_match | dev_null_output) list_files = LISTFILES_NONE; + if (count_matches && list_files == LISTFILES_MATCHING) + { + count_matches_nonzero = true; + list_files = LISTFILES_NONE; + } if ((exit_on_match | dev_null_output) || list_files != LISTFILES_NONE) { count_matches = false; diff -u tests/in-eq-out-infloop.orig tests/in-eq-out-infloop --- tests/in-eq-out-infloop.orig 2024-04-28 18:32:29.435077799 -0400 +++ tests/in-eq-out-infloop 2024-04-28 17:56:59.254957675 -0400 @@ -29,7 +29,7 @@ compare err.exp err || fail=1 # But with each of the following options it must not exit-2. - for i in -q -m1 -l -L; do + for i in -q -m1 -l -L -c; do timeout 10 grep $i 0 $arg < out >> out 2> err; st=$? test $st = 2 && fail=1 done diff -u tests/options.orig tests/options --- tests/options.orig 2024-04-28 18:33:47.645931404 -0400 +++ tests/options 2024-04-28 18:00:23.701573443 -0400 @@ -12,6 +12,9 @@ # grep [ -E| -F][ -c| -l| -q ][-insvx][-e pattern_list] # -f pattern_file ... [file ...] # grep [ -E| -F][ -c| -l| -q ][-insvx] pattern_list [file...] +# +# Also checks that the option combination "-c -l" only reports files +# with non-zero counts. . "${srcdir=.}/init.sh"; path_prepend_ ../src @@ -46,4 +49,63 @@ fail=1 fi +# check the option combination -c -l +echo 'This file contains foo.' > options.in.foo +echo 'This file contains bar.' > options.in.bar + +# check without options +output=$( grep foo options.in.* > /dev/null 2>&1 ) +if test $? -ne 0 ; then + echo "Options: Wrong status code, test #5a failed" + fail=1 +fi +if test "$output" -ne "options.in.foo:This file contains foo." ; then + echo "Options: Wrong output, test #5a failed: $output" + fail=1 +fi + +# check with -c +output=$( grep -c foo options.in.* > /dev/null 2>&1 ) +if test $? -ne 0 ; then + echo "Options: Wrong status code, test #5b failed" + fail=1 +fi +if test "$output" -ne "options.in.foo:1 options.in.bar:0" ; then + echo "Options: Wrong output, test #5b failed: $output" + fail=1 +fi + +# check with -l +output=$( grep -l foo options.in.* > /dev/null 2>&1 ) +if test $? -ne 0 ; then + echo "Options: Wrong status code, test #5c failed" + fail=1 +fi +if test "$output" -ne "options.in.foo" ; then + echo "Options: Wrong output, test #5c failed: $output" + fail=1 +fi + +# check with -c -l +output=$( grep -c -l foo options.in.* > /dev/null 2>&1 ) +if test $? -ne 0 ; then + echo "Options: Wrong status code, test #5d failed" + fail=1 +fi +if test "$output" -ne "options.in.foo:1" ; then + echo "Options: Wrong output, test #5d failed: $output" + fail=1 +fi + +# check with -v -c -l +output=$( grep -v -c -l foo options.in.* > /dev/null 2>&1 ) +if test $? -ne 0 ; then + echo "Options: Wrong status code, test #5e failed" + fail=1 +fi +if test "$output" -ne "options.in.bar:1" ; then + echo "Options: Wrong output, test #5e failed: $output" + fail=1 +fi + Exit $fail