From unknown Sun Jun 15 07:53:32 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#45432 <45432@debbugs.gnu.org> To: bug#45432 <45432@debbugs.gnu.org> Subject: Status: Use both --include and --exclude at the same time Reply-To: bug#45432 <45432@debbugs.gnu.org> Date: Sun, 15 Jun 2025 14:53:32 +0000 retitle 45432 Use both --include and --exclude at the same time reassign 45432 grep submitter 45432 "Fred .Flintstone" severity 45432 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 25 11:57:01 2020 Received: (at submit) by debbugs.gnu.org; 25 Dec 2020 16:57:01 +0000 Received: from localhost ([127.0.0.1]:58099 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksqOj-0000YQ-Cy for submit@debbugs.gnu.org; Fri, 25 Dec 2020 11:57:01 -0500 Received: from lists.gnu.org ([209.51.188.17]:52766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ksmyd-0003bz-HJ for submit@debbugs.gnu.org; Fri, 25 Dec 2020 08:17:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksmyb-0001Gg-Ld for bug-grep@gnu.org; Fri, 25 Dec 2020 08:17:51 -0500 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:44724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ksmyY-00089X-VL for bug-grep@gnu.org; Fri, 25 Dec 2020 08:17:49 -0500 Received: by mail-ej1-x634.google.com with SMTP id w1so6259327ejf.11 for ; Fri, 25 Dec 2020 05:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=wxbeErxadUB4WhDsV00GARC3frz85N29m60+2jz1y/8=; b=tu4vSyOPX9oWibahvAvsj5YiJFMQGxTrxrqsSMHXexXA9Cjs9YG2vs8MrnwJTduDCH gzr1EjTmSSQ6M+K3ILq1WyNgcdIVCAqBmYVaqawkRjT4U70e3u7blCe+qp3y28tBN3tH 1swMI9+E3e/AxrDtojNS/ogAnbL/sVxeJ0isUoTuW2d+nn23k4IOtcduTjBOMhM+oSdD HUHIVlvCa28wu/zPPzsCq8vfGdbwCi+Emgptte8UR/OcI2Mj0FnP5O7Ie12guYXDeTTA j7Z0qEJ0PqKqMRFPoGL4HV50TRiknjUvNRYtQAFr1G/Lj2omO/68pdi4BZx5WlWqJmgr Dqlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=wxbeErxadUB4WhDsV00GARC3frz85N29m60+2jz1y/8=; b=Hv6XqtlsYR65XDuKqqYc/S8Sq54hzsIT7DaAmgTXl5FI2PBXk8DvdFkwApehLW3iWu 196sdF8/q5acuD5H+z2xZq337qgYviw/8EHhFDT8sqJpZAafcWZD8I9s4EYewnoDaTHH +/Dt0NZGnKLOIUJBumsws77xQR36HHgVJt8QN81ilyZHGoh+ZQk9mVMH8GEeYoQ0EZrt 71kTOolm0hJtV2hlIbR2P/RKy2CNHqRah40+PPeZdg7E3HfdLY1oES7t7ZzIQwdisPb4 yF8vy663sFTJDDrFCHWA5wwz0GbHzqwroGrB2tMkgtsWmSToGhYWOov3JLjW3EsMK1Kl 13/g== X-Gm-Message-State: AOAM532Skm4va5ge11uOw10gkMjQu+8TpFrIF7yIW2c3teQbZkgWljDi vnXxxTHv7X47qEZPFNlR3dXLpjPi+W1EmWYUS9dOM+d2s/I= X-Google-Smtp-Source: ABdhPJx33JapaFCxlwCVc74jKURq69Fo/bUJUJdNp2h4TrpVM0UycqJA3T0X8oRHHXvEv4oAVzXoa9oh45WIQWXwz4c= X-Received: by 2002:a17:906:a011:: with SMTP id p17mr31125339ejy.30.1608902263483; Fri, 25 Dec 2020 05:17:43 -0800 (PST) MIME-Version: 1.0 From: "Fred .Flintstone" Date: Fri, 25 Dec 2020 14:17:32 +0100 Message-ID: Subject: Use both --include and --exclude at the same time To: bug-grep@gnu.org Content-Type: multipart/alternative; boundary="000000000000e4b1bc05b749bf72" Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=eldmannen@gmail.com; helo=mail-ej1-x634.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) BAYES_40=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 25 Dec 2020 11:57:00 -0500 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: -2.3 (--) --000000000000e4b1bc05b749bf72 Content-Type: text/plain; charset="UTF-8" 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/*" --000000000000e4b1bc05b749bf72 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

It seems --exclude does = nothing when --include is used. It would be useful to be able to use both t= ogether, in order to do things such as recusively grepping files of a certa= in file extension while excluding certain directories.

=
Example:
$ grep --recursive --include=3D"*.cs" --e= xclude=3D"*/tests/*"
--000000000000e4b1bc05b749bf72-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 04 12:56:07 2021 Received: (at 45432) by debbugs.gnu.org; 4 Jan 2021 17:56:07 +0000 Received: from localhost ([127.0.0.1]:60210 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwU5P-0004mn-JZ for submit@debbugs.gnu.org; Mon, 04 Jan 2021 12:56:07 -0500 Received: from mail-wr1-f43.google.com ([209.85.221.43]:39772) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwU5N-0004mI-As for 45432@debbugs.gnu.org; Mon, 04 Jan 2021 12:56:05 -0500 Received: by mail-wr1-f43.google.com with SMTP id c5so33053567wrp.6 for <45432@debbugs.gnu.org>; Mon, 04 Jan 2021 09:56:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=JoUlCdGkXykRtxvJzjAj8fnWsVtQaePnj/ITDF3IF+c=; b=OkRGyVBs5pGijQ49UfSUPEL3n2NwQM3xesxuJfjYt4yWvR1VNe9+GHALXNfuHa0o8O jYIlTzqPQo8cG0oZd4p8zHKsh0agbdwDnXUKAiql36Kuz3JtLDFwCnTVcKZoPP4Nl52H BhS03EYOci6wrNuriKazG4BcCSqXBCkQqQ9W++yZ4FZpkyANvnNZ8qJx0ffrvciRbGeb NsU3XVZ083ZqkfBbaCG7W0u6o/ejCvUR1Pt5gUuy98zCQfgLjVZWQeEH7CuZ/8szBOrn bPetJXDArRBMrtuyjGqznkDMjPh1mGcQUEUwmocOSYlCUkQFZvMBY5ubcRP9Bs/0XKAe eWlg== X-Gm-Message-State: AOAM5325Azj2VNZ9HxkEOiiO01sIcRBBgm3UrJoiM1u7s/SgXlhoeKF5 CdyhR8dSFUrJ9ftfYQW7wYCPu8Q6pP7ZPYIjR6M= X-Google-Smtp-Source: ABdhPJzgm+a3nhDl5LF66+T1vMYrzMVpS0Wc02bpHWKd/rU4x3I1JYomkLwg5tL97YNHAkb5Ebx0liQlNzvyVeMI3z0= X-Received: by 2002:a5d:44c6:: with SMTP id z6mr81064730wrr.306.1609782959492; Mon, 04 Jan 2021 09:55:59 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jim Meyering Date: Mon, 4 Jan 2021 09:55:48 -0800 Message-ID: Subject: Re: bug#45432: Use both --include and --exclude at the same time To: "Fred .Flintstone" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 45432 Cc: 45432@debbugs.gnu.org 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: -0.5 (/) tags 45432 moreinfo stop On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone wrot= e: > It seems --exclude does nothing when --include is used. It would be usefu= l > 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=3D"*.cs" --exclude=3D"*/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: =E2=80=98--include=3DGLOB=E2=80=99 Search only files whose name matches GLOB, using wildcard matching as described under =E2=80=98--exclude=E2=80=99. If contradictory =E2= =80=98--include=E2=80=99 and =E2=80=98--exclude=E2=80=99 options are given, the last matching one w= ins. If no =E2=80=98--include=E2=80=99 or =E2=80=98--exclude=E2=80=99 options mat= ch, a file is included unless the first such option is =E2=80=98--include=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 08:27:44 2021 Received: (at 45432) by debbugs.gnu.org; 5 Jan 2021 13:27:44 +0000 Received: from localhost ([127.0.0.1]:41092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwmNE-0005Er-6R for submit@debbugs.gnu.org; Tue, 05 Jan 2021 08:27:44 -0500 Received: from mailgw07.kcn.ne.jp ([61.86.7.214]:59061) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kwmNC-0005EZ-OG for 45432@debbugs.gnu.org; Tue, 05 Jan 2021 08:27:43 -0500 Received: from mxs01-s (mailgw1.kcn.ne.jp [61.86.15.233]) by mailgw07.kcn.ne.jp (Postfix) with ESMTP id 45C274100E for <45432@debbugs.gnu.org>; Tue, 5 Jan 2021 22:27:35 +0900 (JST) X-matriXscan-loop-detect: a2d0c8df49889451b22158e1f215204166513ad2 Received: from mail14.kcn.ne.jp ([61.86.6.132]) by mxs01-s with ESMTP; Tue, 05 Jan 2021 22:27:32 +0900 (JST) Received: from [10.120.1.62] (i118-21-128-66.s30.a048.ap.plala.or.jp [118.21.128.66]) by mail14.kcn.ne.jp (Postfix) with ESMTPA id 305CD40A8510; Tue, 5 Jan 2021 22:27:32 +0900 (JST) Date: Tue, 05 Jan 2021 22:27:30 +0900 From: Norihiro Tanaka To: Jim Meyering Subject: Re: bug#45432: Use both --include and --exclude at the same time In-Reply-To: References: Message-Id: <20210105222730.52AC.27F6AC2D@kcn.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-2022-JP" Content-Transfer-Encoding: 7bit X-Mailer: Becky! ver. 2.75.01 [ja] X-matriXscan-msec-AV: Clean X-matriXscan-Action: Approve X-matriXscan: Uncategorized X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 45432 Cc: "Fred .Flintstone" , 45432@debbugs.gnu.org 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.0 (-) On Mon, 4 Jan 2021 09:55:48 -0800 Jim Meyering wrote: > tags 45432 moreinfo > stop > > On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone 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/*" From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 06 17:08:22 2021 Received: (at 45432) by debbugs.gnu.org; 6 Jan 2021 22:08:22 +0000 Received: from localhost ([127.0.0.1]:45789 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxGyc-00052W-9x for submit@debbugs.gnu.org; Wed, 06 Jan 2021 17:08:22 -0500 Received: from mail-ed1-f51.google.com ([209.85.208.51]:44639) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxFAQ-00022Z-UQ for 45432@debbugs.gnu.org; Wed, 06 Jan 2021 15:12:27 -0500 Received: by mail-ed1-f51.google.com with SMTP id p22so5495825edu.11 for <45432@debbugs.gnu.org>; Wed, 06 Jan 2021 12:12:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LdtZ8HRMR69UNYHXKtmn+n6zavKu8737HgB4cxH0Nn8=; b=c1FLcE93uTwiKNH6U5vhj+Db3ma3vq2EnR0y28OFhowAUAQIdd2Ds0awF92s4u5Ssu c0l2mYSdvE8Xm8EBrG9djEGvgywth20uGNvMhSDuR7/+Y4wp6U3pt/CrE25EkdqQK2Mk hTOeDe3S6JHFbq4CdwBxQmVo/DMoxoCHI3qBEcoivhIXd0KLQIo3T4PmU2gF+jJuK8Tj B2aSqS4ifK/iUlRm9JE8LcxaZ+AIweeyR0Qu31DxXZG60ftb6U627Ot2LrTkxWTcHzQ3 g6l6juchlPLBr+9NY4vCTzaTCdBTx2MldkBGB0b2T+gRC7is7qAl6TeeYYCy18Pz88Rq w3wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LdtZ8HRMR69UNYHXKtmn+n6zavKu8737HgB4cxH0Nn8=; b=Quoha3mccaahpaRLDDAX3Ej3aKfr+6+cy8utMlNxKJ6Vkj7rVwRTJbZ7arXlRe818P kHoNJbQDUXcp1meHM0cUZ7ku9YeBmrdSAXl37rFax52W3+xLgkEVauQm44VOcDKF1Rvc zp8OgvBfBfP4lqBBv21JxJ28Q1CE04XxErqB3SUvzF/Mfb8hhq1VogWo9y8U5JiAoFtq MY2LqXsD18UTIvQJKHew+k420t4qyb2PzZTDPl35OaUyyueqRJa9xGa7XclY68XUm6l5 haAEHQA6HYr4oA5kQY8DcqgUI5Ym3MJxeftmUc9EE2eUetyiCriHuEk35iLDoTrM+x6G YcnQ== X-Gm-Message-State: AOAM532kodFx2ypxzKOcfZV4+ms67skd3flG4v7Zq6BQYKehAx3LZzBb 86Se9pu7zFss3oqnZlPGGGJKfv4OKfjSRxRgtb6gDGOw X-Google-Smtp-Source: ABdhPJzGjMZGgYO6aX+APfaQAblukCTK6UNPpxUZ2dx/YMdpoHYtS9P5YAtOXL0EH8NS5wzCZV0IkDbjcla2KHIe7wM= X-Received: by 2002:a50:f61b:: with SMTP id c27mr5040107edn.61.1609963941067; Wed, 06 Jan 2021 12:12:21 -0800 (PST) MIME-Version: 1.0 References: <20210105222730.52AC.27F6AC2D@kcn.ne.jp> In-Reply-To: <20210105222730.52AC.27F6AC2D@kcn.ne.jp> From: "Fred .Flintstone" Date: Wed, 6 Jan 2021 21:12:09 +0100 Message-ID: Subject: Re: bug#45432: Use both --include and --exclude at the same time To: Norihiro Tanaka Content-Type: multipart/alternative; boundary="000000000000cf003105b840f024" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 45432 X-Mailman-Approved-At: Wed, 06 Jan 2021 17:08:20 -0500 Cc: Jim Meyering , 45432@debbugs.gnu.org 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.0 (-) --000000000000cf003105b840f024 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 wrote: > > On Mon, 4 Jan 2021 09:55:48 -0800 > Jim Meyering wrote: > > > tags 45432 moreinfo > > stop > > > > On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone > 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=3D"*.cs" --exclude=3D"*/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: > > > > =E2=80=98--include=3DGLOB=E2=80=99 > > Search only files whose name matches GLOB, using wildcard matching > > as described under =E2=80=98--exclude=E2=80=99. If contradictory = =E2=80=98--include=E2=80=99 and > > =E2=80=98--exclude=E2=80=99 options are given, the last matching o= ne wins. If no > > =E2=80=98--include=E2=80=99 or =E2=80=98--exclude=E2=80=99 options= match, a file is included unless > > the first such option is =E2=80=98--include=E2=80=99. > > 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=3D*.a' '--exclude=3Db/*' x . > ./b/x.a:x > ./a/x.a:x > > Request from him: > $ grep --recursive '--include=3D*.a' '--exclude=3Db/*' x . > ./a/x.a:x > > It means "*.a expept b/*" > > --000000000000cf003105b840f024 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 integrat= ion tests.

On Tue, Jan 5, 2021 at 2:27 PM Norihiro Tanaka <noritnk@kcn.ne.jp> wrote:
=

On Mon, 4 Jan 2021 09:55:48 -0800
Jim Meyering <jim@= meyering.net> wrote:

> tags 45432 moreinfo
> stop
>
> On Fri, Dec 25, 2020 at 8:57 AM Fred .Flintstone <eldmannen@gmail.com> wrote:<= br> > > 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 re= cusively
> > grepping files of a certain file extension while excluding certai= n
> > directories.
> >
> > Example:
> > $ grep --recursive --include=3D"*.cs" --exclude=3D"= ;*/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:
>
> =E2=80=98--include=3DGLOB=E2=80=99
>=C2=A0 =C2=A0 =C2=A0 Search only files whose name matches GLOB, using w= ildcard matching
>=C2=A0 =C2=A0 =C2=A0 as described under =E2=80=98--exclude=E2=80=99.=C2= =A0 If contradictory =E2=80=98--include=E2=80=99 and
>=C2=A0 =C2=A0 =C2=A0 =E2=80=98--exclude=E2=80=99 options are given, the= last matching one wins.=C2=A0 If no
>=C2=A0 =C2=A0 =C2=A0 =E2=80=98--include=E2=80=99 or =E2=80=98--exclude= =E2=80=99 options match, a file is included unless
>=C2=A0 =C2=A0 =C2=A0 the first such option is =E2=80=98--include=E2=80= =99.

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=3D*.a' '--exclude=3Db/*' x .<= br> ./b/x.a:x
./a/x.a:x

Request from him:
$ grep --recursive '--include=3D*.a' '--exclude=3Db/*' x .<= br> ./a/x.a:x

It means "*.a expept b/*"

--000000000000cf003105b840f024-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 07 01:16:52 2021 Received: (at 45432) by debbugs.gnu.org; 7 Jan 2021 06:16:52 +0000 Received: from localhost ([127.0.0.1]:46158 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxObL-0008I7-Sa for submit@debbugs.gnu.org; Thu, 07 Jan 2021 01:16:52 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:50390) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxObI-0008Ht-Vo for 45432@debbugs.gnu.org; Thu, 07 Jan 2021 01:16:50 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id F35F81600F1; Wed, 6 Jan 2021 22:16:42 -0800 (PST) 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 cgTUqkYAZTje; Wed, 6 Jan 2021 22:16:42 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5C1D1160122; Wed, 6 Jan 2021 22:16:42 -0800 (PST) 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 hspx5OkgXqeZ; Wed, 6 Jan 2021 22:16:42 -0800 (PST) Received: from [192.168.1.9] (cpe-23-243-218-95.socal.res.rr.com [23.243.218.95]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 399AC1600F1; Wed, 6 Jan 2021 22:16:42 -0800 (PST) Subject: Re: bug#45432: Use both --include and --exclude at the same time To: "Fred .Flintstone" , Norihiro Tanaka References: <20210105222730.52AC.27F6AC2D@kcn.ne.jp> From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: Date: Wed, 6 Jan 2021 22:16:41 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.5 (--) X-Debbugs-Envelope-To: 45432 Cc: 45432@debbugs.gnu.org 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: -3.5 (---) 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 From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 07 01:53:46 2021 Received: (at submit) by debbugs.gnu.org; 7 Jan 2021 06:53:46 +0000 Received: from localhost ([127.0.0.1]:46201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxPB4-0000oC-Jp for submit@debbugs.gnu.org; Thu, 07 Jan 2021 01:53:46 -0500 Received: from lists.gnu.org ([209.51.188.17]:52420) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxPB3-0000o5-E6 for submit@debbugs.gnu.org; Thu, 07 Jan 2021 01:53:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxPB3-00087y-2s for bug-grep@gnu.org; Thu, 07 Jan 2021 01:53:45 -0500 Received: from wforward4-smtp.messagingengine.com ([64.147.123.34]:58033) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxPAy-0000WA-QX for bug-grep@gnu.org; Thu, 07 Jan 2021 01:53:44 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailforward.west.internal (Postfix) with ESMTP id 2957116F8 for ; Thu, 7 Jan 2021 01:53:38 -0500 (EST) Received: from imap21 ([10.202.2.71]) by compute1.internal (MEProxy); Thu, 07 Jan 2021 01:53:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=XSgrPu dO+uhqTT4XNtx2oxxyf8bLm6libVQGFzsKsiI=; b=DYJ/ZxiOwqVxyauVD0RyEL V8q9Y2T0ZlwBZ35z4Us89rVHHpcTaEGOXOyjEkYzzvVuUDwK58NtuNiNiKC2cfXs +EGv2cGOc5P6YlFO133zWuxJmxfdJ9bor2ufxgWgPQzM3WSQprz3jCzja1pyyvaP oNHJe8InmeO1v0rDGVTyni9MLGHAqWJTFSmuVS7NJ5Fi2908Ph0V34CqT6BXbw// q13JH9IEz9gS8pVdgx2vsxJpJUt94AaMD5f+46BuYXgR8hhGF3xkLSX/GJ6rgok8 eLuGMisnxweL3dDBejHrFUwRMUtDHEd3wV1780y5crM6ctLKn66UJzbt92DduX0w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdeguddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsehttd ertderredtnecuhfhrohhmpedfrfgruhhlucflrggtkhhsohhnfdcuoehpjhesuhhsrgdr nhgvtheqnecuggftrfgrthhtvghrnhepleektdetfeefveehffehgeefueffleefjeeuff egfeekhffhheeiieefgfdthfevnecuffhomhgrihhnpehthhgvphihthhhohhnihgttgho fidruhhsnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epphhjsehushgrrdhnvght X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 273266F60060; Thu, 7 Jan 2021 01:52:43 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.1-61-gb52c239-fm-20201210.001-gb52c2396 Mime-Version: 1.0 Message-Id: <9c4a51b3-038a-4c28-91be-3455bd5190f0@www.fastmail.com> In-Reply-To: References: <20210105222730.52AC.27F6AC2D@kcn.ne.jp> Date: Thu, 07 Jan 2021 00:51:43 -0600 From: "Paul Jackson" To: bug-grep@gnu.org Subject: Re: bug#45432: Use both --include and --exclude at the same time Content-Type: text/plain Received-SPF: neutral client-ip=64.147.123.34; envelope-from=pj@usa.net; helo=wforward4-smtp.messagingengine.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_NEUTRAL=0.779 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) 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: -2.6 (--) 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 ... . 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@usa.net From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 07 07:59:01 2021 Received: (at 45432) by debbugs.gnu.org; 7 Jan 2021 12:59:01 +0000 Received: from localhost ([127.0.0.1]:46777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxUsX-0003qq-8H for submit@debbugs.gnu.org; Thu, 07 Jan 2021 07:59:01 -0500 Received: from mail-ed1-f41.google.com ([209.85.208.41]:45095) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxUsV-0003qc-C5 for 45432@debbugs.gnu.org; Thu, 07 Jan 2021 07:59:00 -0500 Received: by mail-ed1-f41.google.com with SMTP id r5so7581354eda.12 for <45432@debbugs.gnu.org>; Thu, 07 Jan 2021 04:58:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RTx32f0ilPuJdRonX0G8/YPQlNROVCIbJckLNYHKbHc=; b=FyTAzD0RueMObtKCDEZ25BQeUid6hasoJw2iwU1cfaWEgSvFbHSXZL12Rnpd8gccK3 BdYnhMm2VVDvWoQkbgb76A6Sjr96Sg3Gmu3fC5EuLXMpqtyd9poh4WoX9K0XlUH368gk iJiTUqkcDGRe3BEYWKzl0xAYcDccjTGNVeeo5zY8jl1bWzMLHW8UTWafq1mdaKWOl8W9 qWpkGbA1KamXW1Oe1czzP0ar2cxalmq2yEu0CB85PuVHKpUmyA00KBzCQBAJaZg7VH8y CUoHGJ4VAQY+Sk8yBQwoqiU9mEpiBvEA8npi/QjmPB5dJgKkyHV5roVqdENKVHLBVkMP Rb9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RTx32f0ilPuJdRonX0G8/YPQlNROVCIbJckLNYHKbHc=; b=hcM1eWsEtej4r3fibfh3eRapoFEn4MtNti+QE1dOHko1JdnThvzrV8mXpiP0ATpuR/ BMV7J8n8QPzFNmzf4+L3xlhUkDlS8kCxjEnD8ROO5wDQD1mTDAqvg+u2aeAHqm+sDji3 +mTxeVDRnnGLVwA5+HEc+JCtfe2PvuoBotwYaBSSAIkScDlkSGeGwD0h12AC7IqA7RRK ys5zTurXXWfD+CJVzrxM6sQIwL4c4Hc6UtHcDNOZ30hF7CtK5NklRIDwqCxc7nWSYMV2 zW8Vn0yhTWPQpHXnbBFWN/Sc7ehzu+CQkXWgi8vfHtUfvfirJgghZcgQ3twFoVq1QWY+ mvnA== X-Gm-Message-State: AOAM5337SJIJIo3CG60FlpfJNTGVxfI41dKxsSRYW65ljUi+aRWFDRgx PIgC612Pth9XWve6thyikcuwKJuTSQyv3kCTyIw= X-Google-Smtp-Source: ABdhPJxINLRBvwEt/K7wLbBBxhNt69tHMyJgI7XGx9pYgLTNWEwpUHuXXuK8CIzw5TAIfdDxeuLdX3yJOWrdefVpeJg= X-Received: by 2002:aa7:d2c9:: with SMTP id k9mr1597699edr.74.1610024333500; Thu, 07 Jan 2021 04:58:53 -0800 (PST) MIME-Version: 1.0 References: <20210105222730.52AC.27F6AC2D@kcn.ne.jp> In-Reply-To: From: "Fred .Flintstone" Date: Thu, 7 Jan 2021 13:58:42 +0100 Message-ID: Subject: Re: bug#45432: Use both --include and --exclude at the same time To: Paul Eggert Content-Type: multipart/alternative; boundary="0000000000007a63de05b84f009a" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 45432 Cc: Norihiro Tanaka , 45432@debbugs.gnu.org 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.0 (-) --0000000000007a63de05b84f009a Content-Type: text/plain; charset="UTF-8" Thanks! I didn't know about the --exclude-dir option. On Thu, Jan 7, 2021 at 7:16 AM Paul Eggert 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 > --0000000000007a63de05b84f009a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks!

I didn't kn= ow about the --exclude-dir option.

--0000000000007a63de05b84f009a-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 08 15:24:10 2021 Received: (at control) by debbugs.gnu.org; 8 Jan 2021 20:24:10 +0000 Received: from localhost ([127.0.0.1]:50758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxyIr-0007WT-SI for submit@debbugs.gnu.org; Fri, 08 Jan 2021 15:24:10 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:60612) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxyIq-0007WG-I2 for control@debbugs.gnu.org; Fri, 08 Jan 2021 15:24:08 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1B95C160099 for ; Fri, 8 Jan 2021 12:24:03 -0800 (PST) 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 Ry_oeqH6EJXP for ; Fri, 8 Jan 2021 12:24:02 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7B1C41600CD for ; Fri, 8 Jan 2021 12:24:02 -0800 (PST) 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 np5msz2aiXvD for ; Fri, 8 Jan 2021 12:24:02 -0800 (PST) Received: from [192.168.1.9] (cpe-23-243-218-95.socal.res.rr.com [23.243.218.95]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 5D110160099 for ; Fri, 8 Jan 2021 12:24:02 -0800 (PST) To: control@debbugs.gnu.org From: Paul Eggert Subject: 45432 is closed Organization: UCLA Computer Science Department Message-ID: <9354b61f-8be6-5e0f-8f6d-b5855c3b11ce@cs.ucla.edu> Date: Fri, 8 Jan 2021 12:24:02 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) 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: -3.3 (---) close 45432 thanks question has been answered From unknown Sun Jun 15 07:53:32 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 06 Feb 2021 12:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator