0

I am on Windows 10, using GNU grep 2.10.

Update: The question has been answered, but I now realize the premise of this question is wrong, because it turns out I must've had some typo that I didn't see even after re-reading my commands multiple times. There is nothing wrong with the grep included in nuwen.net. Thank you Stephan T. Lavavej. I will keep this answer up because it still taught me something that the previous question (linked below) did not.

Original question as follows:

As explained in this question, multiple --include statements can be used to search multiple file extensions.

However, I experienced an issue when I have multiple file extensions that only differ in capitalization.

grep -ri "foo" --include="*.h" --include="*.H" .

The above command will only search through .h files, and not .H files.

grep -ri "foo" --include="*.H" --include="*.h" .

The above command now will only search through .H files, and not .h files.

So apparently, it is only processing the first --include argument because it considers the second to be a duplicate, but then it doesn't search both .H and .h.

My question is: How do I get GNU grep on Windows to search both (and only both) file extensions?

Talset
  • 61
  • 2
  • 18
  • 1
    From where did you get a Windows version of GNU grep 2.10? I cannot reproduce this with GNU grep 2.5.4 from GnuWin32. Anyway, try `grep -ri "foo" --include="*.[Hh]"`. – AlexP May 17 '18 at 22:43
  • Aha, thank you. I had tried doing the {Hh} syntax, but didn't know about the [Hh] syntax. If you want to write that as an answer, I'll certainly accept it. – Talset May 17 '18 at 23:13
  • To answer your question: I did some research. I have been using the grep that came bundled with the MinGW download in https://nuwen.net/mingw.html from June 2017, meaning that it had a grep version from 2012, according to the version history. I believe the author of the website may have custom built it themselves from the following link: https://ftp.gnu.org/gnu/grep/ but I am not certain. The current version on their website says it uses grep 3.1, and the bug no longer exists (although now it uses different highlighting colors that I don't like, but that's off-topic). – Talset May 17 '18 at 23:17

1 Answers1

1

You may want to try

grep -ri "foo" --include="*.[Hh]"

which should search both files ending in H and those ending in h. The manual page for grep says

A pattern can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character literally.

AlexP
  • 4,370
  • 15
  • 15