GNU bug report logs - #52851
git grep feature: boolean logic

Previous Next

Package: grep;

Reported by: Kevin Connor Arpe <kevinarpe <at> gmail.com>

Date: Tue, 28 Dec 2021 14:56:01 UTC

Severity: wishlist

To reply to this bug, email your comments to 52851 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#52851; Package grep. (Tue, 28 Dec 2021 14:56:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kevin Connor Arpe <kevinarpe <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Tue, 28 Dec 2021 14:56:02 GMT) Full text and rfc822 format available.

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

From: Kevin Connor Arpe <kevinarpe <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: git grep feature: boolean logic
Date: Tue, 28 Dec 2021 22:55:32 +0800
[Message part 1 (text/plain, inline)]
Hello,

Recently, I was stumped with a difficult grep problem: I needed to filter
files containing more than one regex (think: logical-and).  I didn't know
how to do this using only a single invocation of GNU grep.  (Please correct
me if I am wrong.)

A bunch of Googling led me to discover that git has a grep sub-command that
implements boolean logic with and/or/not/parens operators.  Manpage:
https://git-scm.com/docs/git-grep, Source:
https://github.com/git/git/blob/master/grep.c

At the moment, it's not possible to use git grep very well outside of git
repositories.  There are some issues around absolute and relative paths,
plus "git working directory".

Eventually, I settled on writing a crude shell script that wraps GNU grep
to provide similar functionality.  However, I am aware of its inefficiency,
as it requires multiple invocations of grep.

Are people aware of this very cool grep feature with boolean logic?  I
tried to search the GNU grep message archive, but I didn't see any
discussion about it.  I'm curious what the GNU grep team thinks about this
feature.

Kind regards,
Kevin Arpe
Hongkong
[Message part 2 (text/html, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#52851; Package grep. (Tue, 28 Dec 2021 15:45:01 GMT) Full text and rfc822 format available.

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

From: arnold <at> skeeve.com
To: kevinarpe <at> gmail.com, 52851 <at> debbugs.gnu.org
Subject: Re: bug#52851: git grep feature: boolean logic
Date: Tue, 28 Dec 2021 08:44:14 -0700
Hi.

You may want a different tool:

	awk '/pattern1/ && /pattern2/' ...
	awk '/pattern1/ || /pattern2/' ...
	awk '/pattern1/ && !/pattern2/' ...

And so on.

Seems much easier than stuffing boolean logic into grep.

Just a thought,

Arnold

Kevin Connor Arpe <kevinarpe <at> gmail.com> wrote:

> Hello,
>
> Recently, I was stumped with a difficult grep problem: I needed to filter
> files containing more than one regex (think: logical-and).  I didn't know
> how to do this using only a single invocation of GNU grep.  (Please correct
> me if I am wrong.)
>
> A bunch of Googling led me to discover that git has a grep sub-command that
> implements boolean logic with and/or/not/parens operators.  Manpage:
> https://git-scm.com/docs/git-grep, Source:
> https://github.com/git/git/blob/master/grep.c
>
> At the moment, it's not possible to use git grep very well outside of git
> repositories.  There are some issues around absolute and relative paths,
> plus "git working directory".
>
> Eventually, I settled on writing a crude shell script that wraps GNU grep
> to provide similar functionality.  However, I am aware of its inefficiency,
> as it requires multiple invocations of grep.
>
> Are people aware of this very cool grep feature with boolean logic?  I
> tried to search the GNU grep message archive, but I didn't see any
> discussion about it.  I'm curious what the GNU grep team thinks about this
> feature.
>
> Kind regards,
> Kevin Arpe
> Hongkong




Severity set to 'wishlist' from 'normal' Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Tue, 28 Dec 2021 17:40:02 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 173 days ago.

Previous Next


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