GNU bug report logs - #24382
grep should support -l and -n together

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: grep; Severity: wishlist; Reported by: Mathieu Jobin <somekool@HIDDEN>; dated Tue, 6 Sep 2016 15:36:02 UTC; Maintainer for grep is bug-grep@HIDDEN.
Severity set to 'wishlist' from 'normal' Request was from Paul Eggert <eggert@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 6 Sep 2016 16:57:26 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Sep 06 12:57:26 2016
Received: from localhost ([127.0.0.1]:51602 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bhJgc-0004PJ-Js
	for submit <at> 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 <eggert@HIDDEN>) id 1bhJgb-0004P7-7n
 for submit <at> 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 <eggert@HIDDEN>) id 1bhJgV-00018P-21
 for submit <at> 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 <eggert@HIDDEN>) id 1bhJgU-000188-VB
 for submit <at> 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 <eggert@HIDDEN>) id 1bhJgS-0004Hh-N8
 for bug-grep@HIDDEN; Tue, 06 Sep 2016 12:57:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <eggert@HIDDEN>) id 1bhJgP-000173-FV
 for bug-grep@HIDDEN; 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 <eggert@HIDDEN>) id 1bhJgP-00016m-9l
 for bug-grep@HIDDEN; 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 <bug-grep@HIDDEN>; 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 <bug-grep@HIDDEN>;
 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 <bug-grep@HIDDEN>; 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 <bug-grep@HIDDEN>;
 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 <bug-grep@HIDDEN>; Tue,  6 Sep 2016 09:57:11 -0700 (PDT)
Subject: Re: bug#24382: grep should support -l and -n together
To: bug-grep@HIDDEN
References: <CAErp+DJQnKHe7BdUxp7vhLDnhzdSVuXUgYamr8htW7YG-=VxUw@HIDDEN>
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
Message-ID: <dea19395-05ed-41d0-584b-341220b09042@HIDDEN>
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: <CAErp+DJQnKHe7BdUxp7vhLDnhzdSVuXUgYamr8htW7YG-=VxUw@HIDDEN>
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 <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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)





Information forwarded to bug-grep@HIDDEN:
bug#24382; Package grep. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 6 Sep 2016 15:35:36 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Sep 06 11:35:35 2016
Received: from localhost ([127.0.0.1]:51502 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1bhIPK-0000gr-Ph
	for submit <at> 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 <somekool@HIDDEN>) id 1bhHUx-0007cB-LH
 for submit <at> 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 <somekool@HIDDEN>) id 1bhHUr-00009d-H7
 for submit <at> 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 <somekool@HIDDEN>) id 1bhHUr-00008v-Dw
 for submit <at> 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 <somekool@HIDDEN>) id 1bhHUp-00065q-0e
 for bug-grep@HIDDEN; Tue, 06 Sep 2016 10:37:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <somekool@HIDDEN>) id 1bhHUn-00007T-6m
 for bug-grep@HIDDEN; 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 <somekool@HIDDEN>) id 1bhHUn-00007E-2X
 for bug-grep@HIDDEN; Tue, 06 Sep 2016 10:37:05 -0400
Received: by mail-yb0-x22e.google.com with SMTP id d205so60427773ybh.0
 for <bug-grep@HIDDEN>; 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 <somekool@HIDDEN>
Date: Tue, 6 Sep 2016 10:36:22 -0400
Message-ID: <CAErp+DJQnKHe7BdUxp7vhLDnhzdSVuXUgYamr8htW7YG-=VxUw@HIDDEN>
Subject: grep should support -l and -n together
To: bug-grep@HIDDEN
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 <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
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

<div dir=3D"ltr"><div><div><div><div><div><div><div><div><div><div><div>I l=
ike using <br><br></div>&gt; grep -rn pattern dir<br><br></div>a lot becaus=
e it returns all the result with the line numbers<br></div>I think its one =
of the most common use case of grep.<br><br></div>recently I started using =
<br><br></div>&gt; grep -rl pattern dir<br><br></div>only returning the lis=
t of files, without the content appended.<br></div>I find that really usefu=
l<br><br></div>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><=
br></div>for example<br><br>&gt; grep -rln &quot;[^a-z]if .\+ =3D .\+&quot;=
 app=C2=A0 | xargs kate<br><br></div>unfortunately, the line numbers is not=
 present on the grep output here<br><br><br></div><div>should you chose not=
 to support this, then it should probably error out<br><br></div>cheers,<br=
><br clear=3D"all"><div><div><div><div><div><div><div><div><div><div><div><=
div><div><div><br>-- <br><div class=3D"gmail_signature">Mathieu Jobin<br><b=
r></div>
</div></div></div></div></div></div></div></div></div></div></div></div></d=
iv></div></div>

--94eb2c06ebd0ea2544053bd7bafd--




Acknowledgement sent to Mathieu Jobin <somekool@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-grep@HIDDEN. Full text available.
Report forwarded to bug-grep@HIDDEN:
bug#24382; Package grep. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.