Grep not working on Git Bash for Windows

Hi! I have a question about the Grep function in Git for Windows.
I’m just roaming around the git environment, trying some things out, and I can’t seem to search for lines in files in the directory with grep. I tried searching for the word “philosophy” by using the following command:

grep -R philosophy ./*

I also tried searching for the term without the suffixed symbols and with quotationmarks, but nothing comes up, even though I’m sure there’s plenty files that contain this word in the current current directory.
Can anyone help me?
Thank you!g

If you’re using -R for recursive then you don’t need globbing for the directories (consider if you want -r or -R). Is it possible your text is capitalised?

Does grep -iR philosophy behave as expected (where -i ignores case)?

What kind of files that contain this string are you referring to? If they’re not plaintext then it’s possible they may be encoded some way such that philosophy doesn’t appear in plaintext (you could check how the file looks with cat for example) or perhaps use the -a flag for binary files.

1 Like

Aha, I see. the files I was referring to are .docx files. I tried reading the docx file in Git using cat, and I saw that this is unreadable. So it makes sense now. Are there any other files that grep can be used for to read through other than .txt?

Ideally most files designed for human reading and editing are hopefully kept as fairly simple text whenever possible or with a fairly simple markup (though sadly this isn’t always the case). The .docx files I’ve looked at locally are bundled up .xml documents and various bits so the .xml files could be grepped.

The main problem with docx is that the files are compressed too (you’ve probably come across many zipped files when downloading from the internet that must be unpacked before use). Brute force unzip and then using grep technically works though the located string is returned in a mountain of xml but that’s probably a poor way to go about it. If you’re looking specifically to hunt through multiple .docx files I’d suggest a web search for either a nice tool to do this or some guidance on it (or stick with an OS in-built search if you’d rather not).

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.