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

Previous Next

Package: grep;

Reported by: Mathieu Jobin <somekool <at> gmail.com>

Date: Tue, 6 Sep 2016 15:36:02 UTC

Severity: wishlist

To reply to this bug, email your comments to 24382 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#24382; Package grep. (Tue, 06 Sep 2016 15:36:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mathieu Jobin <somekool <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Tue, 06 Sep 2016 15:36:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mathieu Jobin <somekool <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: grep should support -l and -n together
Date: Tue, 6 Sep 2016 10:36:22 -0400
[Message part 1 (text/plain, inline)]
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
[Message part 2 (text/html, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#24382; Package grep. (Tue, 06 Sep 2016 16:58:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: bug-grep <at> gnu.org
Subject: Re: bug#24382: grep should support -l and -n together
Date: Tue, 6 Sep 2016 09:57:11 -0700
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)





Severity set to 'wishlist' from 'normal' Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Tue, 06 Sep 2016 16:59:01 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 288 days ago.

Previous Next


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