GNU bug report logs -
#45432
Use both --include and --exclude at the same time
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45432 in the body.
You can then email your comments to 45432 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-grep <at> gnu.org
:
bug#45432
; Package
grep
.
(Fri, 25 Dec 2020 16:57:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
"Fred .Flintstone" <eldmannen <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-grep <at> gnu.org
.
(Fri, 25 Dec 2020 16:57:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi,
It seems --exclude does nothing when --include is used. It would be useful
to be able to use both together, in order to do things such as recusively
grepping files of a certain file extension while excluding certain
directories.
Example:
$ grep --recursive --include="*.cs" --exclude="*/tests/*"
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-grep <at> gnu.org
:
bug#45432
; Package
grep
.
(Mon, 04 Jan 2021 17:57:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 45432 <at> debbugs.gnu.org (full text, mbox):
tags 45432 moreinfo
stop
On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone <eldmannen <at> gmail.com> wrote:
> It seems --exclude does nothing when --include is used. It would be useful
> to be able to use both together, in order to do things such as recusively
> grepping files of a certain file extension while excluding certain
> directories.
>
> Example:
> $ grep --recursive --include="*.cs" --exclude="*/tests/*"
Can you provide a complete example showing a malfunction?
You've probably already read this from "info grep", but see also
the description of --exclude there:
‘--include=GLOB’
Search only files whose name matches GLOB, using wildcard matching
as described under ‘--exclude’. If contradictory ‘--include’ and
‘--exclude’ options are given, the last matching one wins. If no
‘--include’ or ‘--exclude’ options match, a file is included unless
the first such option is ‘--include’.
Information forwarded
to
bug-grep <at> gnu.org
:
bug#45432
; Package
grep
.
(Tue, 05 Jan 2021 13:28:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 45432 <at> debbugs.gnu.org (full text, mbox):
On Mon, 4 Jan 2021 09:55:48 -0800
Jim Meyering <jim <at> meyering.net> wrote:
> tags 45432 moreinfo
> stop
>
> On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone <eldmannen <at> gmail.com> wrote:
> > It seems --exclude does nothing when --include is used. It would be useful
> > to be able to use both together, in order to do things such as recusively
> > grepping files of a certain file extension while excluding certain
> > directories.
> >
> > Example:
> > $ grep --recursive --include="*.cs" --exclude="*/tests/*"
>
> Can you provide a complete example showing a malfunction?
> You've probably already read this from "info grep", but see also
> the description of --exclude there:
>
> ‘--include=GLOB’
> Search only files whose name matches GLOB, using wildcard matching
> as described under ‘--exclude’. If contradictory ‘--include’ and
> ‘--exclude’ options are given, the last matching one wins. If no
> ‘--include’ or ‘--exclude’ options match, a file is included unless
> the first such option is ‘--include’.
I understand as he requests "AND" condition.
$ mkdir a b
$ touch a/x.a a/x.b b/x.a b/x.b
$ for file in */*; do echo x >$file; done
Current result:
$ grep --recursive '--include=*.a' '--exclude=b/*' x .
./b/x.a:x
./a/x.a:x
Request from him:
$ grep --recursive '--include=*.a' '--exclude=b/*' x .
./a/x.a:x
It means "*.a expept b/*"
Information forwarded
to
bug-grep <at> gnu.org
:
bug#45432
; Package
grep
.
(Wed, 06 Jan 2021 22:09:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 45432 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Yes, I meant like Tanaka said, I want BOTH to include AND exclude.
So I can include only a file extension, and exclude certain directories
such as directories containing unit tests and integration tests.
On Tue, Jan 5, 2021 at 2:27 PM Norihiro Tanaka <noritnk <at> kcn.ne.jp> wrote:
>
> On Mon, 4 Jan 2021 09:55:48 -0800
> Jim Meyering <jim <at> meyering.net> wrote:
>
> > tags 45432 moreinfo
> > stop
> >
> > On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone <eldmannen <at> gmail.com>
> wrote:
> > > It seems --exclude does nothing when --include is used. It would be
> useful
> > > to be able to use both together, in order to do things such as
> recusively
> > > grepping files of a certain file extension while excluding certain
> > > directories.
> > >
> > > Example:
> > > $ grep --recursive --include="*.cs" --exclude="*/tests/*"
> >
> > Can you provide a complete example showing a malfunction?
> > You've probably already read this from "info grep", but see also
> > the description of --exclude there:
> >
> > ‘--include=GLOB’
> > Search only files whose name matches GLOB, using wildcard matching
> > as described under ‘--exclude’. If contradictory ‘--include’ and
> > ‘--exclude’ options are given, the last matching one wins. If no
> > ‘--include’ or ‘--exclude’ options match, a file is included unless
> > the first such option is ‘--include’.
>
> I understand as he requests "AND" condition.
>
> $ mkdir a b
> $ touch a/x.a a/x.b b/x.a b/x.b
> $ for file in */*; do echo x >$file; done
>
> Current result:
> $ grep --recursive '--include=*.a' '--exclude=b/*' x .
> ./b/x.a:x
> ./a/x.a:x
>
> Request from him:
> $ grep --recursive '--include=*.a' '--exclude=b/*' x .
> ./a/x.a:x
>
> It means "*.a expept b/*"
>
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-grep <at> gnu.org
:
bug#45432
; Package
grep
.
(Thu, 07 Jan 2021 06:17:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 45432 <at> debbugs.gnu.org (full text, mbox):
On 1/6/21 12:12 PM, Fred .Flintstone wrote:
> Yes, I meant like Tanaka said, I want BOTH to include AND exclude.
> So I can include only a file extension, and exclude certain directories
> such as directories containing unit tests and integration tests.
grep -r --include='*.cs' --exclude-dir='tests' PATTERN DIR
Information forwarded
to
bug-grep <at> gnu.org
:
bug#45432
; Package
grep
.
(Thu, 07 Jan 2021 06:54:02 GMT)
Full text and
rfc822 format available.
Message #20 received at submit <at> debbugs.gnu.org (full text, mbox):
Being an old school geek, I recommend using the "find" command,
perhaps piped to "xargs grep", to control which files to grep.
The find command has a more general syntax for logically choosing
files, by any property of name, path or stat fields, with possible nested
and, or and not predicates, as needed.
However ... I learned how to use find, xargs and grep long before grep
had any such options as --include and --exclude, so I should probably
be ignored as not contributing to the current discussion.
Carry on ... <chuckle>.
P.S. -- Best use "find -print0" and "xargs -0", in order to avoid some
ancient and regrettable nasty irregularities in how xargs otherwise
handles embedded spaces and unbalanced quotation marks in the
input stream.
See my xargs wrapper for a convenient workaround for this nastiness:
http://thepythoniccow.us/x.c.txt
--
Paul Jackson
pj <at> usa.net
Information forwarded
to
bug-grep <at> gnu.org
:
bug#45432
; Package
grep
.
(Thu, 07 Jan 2021 13:00:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 45432 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Thanks!
I didn't know about the --exclude-dir option.
On Thu, Jan 7, 2021 at 7:16 AM Paul Eggert <eggert <at> cs.ucla.edu> wrote:
> On 1/6/21 12:12 PM, Fred .Flintstone wrote:
> > Yes, I meant like Tanaka said, I want BOTH to include AND exclude.
> > So I can include only a file extension, and exclude certain directories
> > such as directories containing unit tests and integration tests.
>
> grep -r --include='*.cs' --exclude-dir='tests' PATTERN DIR
>
[Message part 2 (text/html, inline)]
bug closed, send any further explanations to
45432 <at> debbugs.gnu.org and "Fred .Flintstone" <eldmannen <at> gmail.com>
Request was from
Paul Eggert <eggert <at> cs.ucla.edu>
to
control <at> debbugs.gnu.org
.
(Fri, 08 Jan 2021 20:25:01 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 06 Feb 2021 12:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 78 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.