From unknown Fri Jun 20 07:19:10 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#24382 <24382@debbugs.gnu.org> To: bug#24382 <24382@debbugs.gnu.org> Subject: Status: grep should support -l and -n together Reply-To: bug#24382 <24382@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:19:10 +0000 retitle 24382 grep should support -l and -n together reassign 24382 grep submitter 24382 Mathieu Jobin severity 24382 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 06 11:35:35 2016 Received: (at submit) by debbugs.gnu.org; 6 Sep 2016 15:35:36 +0000 Received: from localhost ([127.0.0.1]:51502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhIPK-0000gr-Ph for submit@debbugs.gnu.org; Tue, 06 Sep 2016 11:35:35 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59436) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhHUx-0007cB-LH for submit@debbugs.gnu.org; Tue, 06 Sep 2016 10:37:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhHUr-00009d-H7 for submit@debbugs.gnu.org; Tue, 06 Sep 2016 10:37:10 -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.8 required=5.0 tests=AC_DIV_BONANZA,BAYES_50, FREEMAIL_FROM,HTML_MESSAGE,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:39255) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhHUr-00008v-Dw for submit@debbugs.gnu.org; Tue, 06 Sep 2016 10:37:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhHUp-00065q-0e for bug-grep@gnu.org; Tue, 06 Sep 2016 10:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhHUn-00007T-6m for bug-grep@gnu.org; Tue, 06 Sep 2016 10:37:05 -0400 Received: from mail-yb0-x22e.google.com ([2607:f8b0:4002:c09::22e]:32828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhHUn-00007E-2X for bug-grep@gnu.org; Tue, 06 Sep 2016 10:37:05 -0400 Received: by mail-yb0-x22e.google.com with SMTP id d205so60427773ybh.0 for ; Tue, 06 Sep 2016 07:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=YUJv+e+hFSkPTXHQJxxlLerUVArfXVf19RlPeBwi1Ko=; b=L/HgK64mQBSudO83JUgGHJaOolDZLNdBw+eZli5iO0g8ssvw5XKBiF6OQSZaaGc2FF BPZaVrHbNZnLkKNjNdpgiFTkNxkx+5Z1eD5M6MdNkBWMZ1ydeTQN6IrxjoXLA9LkJzPa WjczBi1EhRHFB5BKfmPkU5RXluNM2S3mt2KdnYVW/ymV0fl3o+WdtBipJ7gSrW1iLeph dvPchZQu/dEJc+REP20q4KKoy2Bum95dkhP657tAmGNKZgq8d5r1DxfcZlQBDEvBd8SX KtPtCRZ/Zjf68kT7+TGl7h7/y7Dq6GKF+/PWBBUgZ3oVlXURJOLyvJHGGd5XUQ9Wf4xr Gn9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=YUJv+e+hFSkPTXHQJxxlLerUVArfXVf19RlPeBwi1Ko=; b=GdOYAXYqlS2JSXDYFijkUXC5a61uyeWddgARuGycuB9a7OFKTbG3G9UQjLtecX4RWY q6nc4knT4VckDqb8+8GOwB3B/n9o3KXdX5qPTCwT7WQ7pS/EvVbAP+uKx/QyQD4ZH0bQ McldBAwAN9FSi53yPNHt8OTzcwH2DoSDkokm9nLxUTQ3deg32tmFE51a7vpDioFX/VG7 RFmTMYxpjMcc0l6fX28S+rnAFStZ/vQc3CYDiL1qi7/dBlimhWVX5pjl9XJz31tQj+FG rI9sZh1S3sn9BenJh54PihR0MBGFN7AMVzCVuttn5B/KU3pfPWFbZK2RusrvjcZhkaxr gI7w== X-Gm-Message-State: AE9vXwOfzDHJzD4N9T9MWbXdl88/aZoHgercNu6XzDSyAhLbUm/uGaEXbheDkBRhupAhyGKe6T7pr68Ie2Wheg== X-Received: by 10.107.186.7 with SMTP id k7mr5112135iof.3.1473172623465; Tue, 06 Sep 2016 07:37:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.211.130 with HTTP; Tue, 6 Sep 2016 07:36:22 -0700 (PDT) From: Mathieu Jobin Date: Tue, 6 Sep 2016 10:36:22 -0400 Message-ID: Subject: grep should support -l and -n together To: bug-grep@gnu.org Content-Type: multipart/alternative; boundary=94eb2c06ebd0ea2544053bd7bafd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 06 Sep 2016 11:35:29 -0400 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: -4.0 (----) --94eb2c06ebd0ea2544053bd7bafd Content-Type: text/plain; charset=UTF-8 I like using > grep -rn pattern dir a lot because it returns all the result with the line numbers I think its one of the most common use case of grep. recently I started using > grep -rl pattern dir only returning the list of files, without the content appended. I find that really useful but when using -rl , -n is ignored, which is sad, because I could pipe in my editor and it would open the files at the proper line for example > grep -rln "[^a-z]if .\+ = .\+" app | xargs kate unfortunately, the line numbers is not present on the grep output here should you chose not to support this, then it should probably error out cheers, -- Mathieu Jobin --94eb2c06ebd0ea2544053bd7bafd Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I l= ike using

> grep -rn pattern dir

a lot becaus= e it returns all the result with the line numbers
I think its one = of the most common use case of grep.

recently I started using =

> grep -rl pattern dir

only returning the lis= t of files, without the content appended.
I find that really usefu= l

but when using -rl , -n is ignored, which is sad, because I = could pipe in my editor and it would open the files at the proper line
<= br>
for example

> grep -rln "[^a-z]if .\+ =3D .\+"= app=C2=A0 | xargs kate

unfortunately, the line numbers is not= present on the grep output here


should you chose not= to support this, then it should probably error out

cheers,
<= div>

--
Mathieu Jobin
--94eb2c06ebd0ea2544053bd7bafd-- From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 06 12:57:26 2016 Received: (at submit) by debbugs.gnu.org; 6 Sep 2016 16:57:26 +0000 Received: from localhost ([127.0.0.1]:51602 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhJgc-0004PJ-Js for submit@debbugs.gnu.org; Tue, 06 Sep 2016 12:57:26 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48041) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhJgb-0004P7-7n for submit@debbugs.gnu.org; Tue, 06 Sep 2016 12:57:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhJgV-00018P-21 for submit@debbugs.gnu.org; Tue, 06 Sep 2016 12:57:20 -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.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:35947) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhJgU-000188-VB for submit@debbugs.gnu.org; Tue, 06 Sep 2016 12:57:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhJgS-0004Hh-N8 for bug-grep@gnu.org; Tue, 06 Sep 2016 12:57:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhJgP-000173-FV for bug-grep@gnu.org; Tue, 06 Sep 2016 12:57:16 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:45814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhJgP-00016m-9l for bug-grep@gnu.org; Tue, 06 Sep 2016 12:57:13 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 82320160DFF for ; Tue, 6 Sep 2016 09:57:12 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Bbsz8ADaxKIs for ; Tue, 6 Sep 2016 09:57:11 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 684D116111A for ; Tue, 6 Sep 2016 09:57:11 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id lqnuXw_CIPSg for ; Tue, 6 Sep 2016 09:57:11 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 51CE7160DFF for ; Tue, 6 Sep 2016 09:57:11 -0700 (PDT) Subject: Re: bug#24382: grep should support -l and -n together To: bug-grep@gnu.org References: From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Tue, 6 Sep 2016 09:57:11 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.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: -4.0 (----) On 09/06/2016 07:36 AM, Mathieu Jobin wrote: > should you chose not to support this, then it should probably error out Hmm, well, as I understand it POSIX requires that -n be ignored if -l is also specified; see: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html I suppose we could add an option saying "please output file names and line numbers but not line contents". This option would act like -o, except it would omit all the line contents instead of just the non-matching part. Seems like a bit of a specialized use, though. Can't you get something close to what you want, by asking the editor to search for the matching lines? For vi, you can do the following, and I assume your editor has a similar option: vi +/PATTERN $(grep -l PATTERN FILES) From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 06 12:58:11 2016 Received: (at control) by debbugs.gnu.org; 6 Sep 2016 16:58:11 +0000 Received: from localhost ([127.0.0.1]:51608 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhJhK-0004Qo-T1 for submit@debbugs.gnu.org; Tue, 06 Sep 2016 12:58:11 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:57612) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhJhJ-0004QY-BM for control@debbugs.gnu.org; Tue, 06 Sep 2016 12:58:09 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8EE71160DFF for ; Tue, 6 Sep 2016 09:58:03 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id rHPxp6tRZRZy for ; Tue, 6 Sep 2016 09:58:02 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E05F516111A for ; Tue, 6 Sep 2016 09:58:02 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id TeV6oVh99uGy for ; Tue, 6 Sep 2016 09:58:02 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id CA5A9160DFF for ; Tue, 6 Sep 2016 09:58:02 -0700 (PDT) To: control@debbugs.gnu.org From: Paul Eggert Subject: 24382 is wishlist Organization: UCLA Computer Science Department Message-ID: <9c713cb6-a40d-fc06-2982-b102ed117c69@cs.ucla.edu> Date: Tue, 6 Sep 2016 09:58:02 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.1 (-) 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: -1.1 (-) severity 24382 wishlist