I need to do a recursive grep in Windows, something like this in Unix/Linux:
grep -i 'string' `find . -print`
or the more-preferred method:
find . -print | xargs grep -i 'string'
I'm stuck with just cmd.exe, so I only have Windows built-in commands. I can't install Cygwin, or any 3rd party tools like UnxUtils on this server unfortunately. I'm not even sure I can install PowerShell. Any suggestions using only cmd.exe built-ins (Windows 2003 Server)?
Select-String
worked best for me. All the other options listed here, such asfindstr
, didn't work with large files.Here's an example:
note: This requires Powershell
The parameters have the following meanings:
s
= recursivep
= skip non-printable charactersi
= case insensitiven
= print line numbersAnd the string to search for is the bit you put in quotes after
/c:
If you have Perl installed, you could use ack, available at http://beyondgrep.com/.
I just searched a text with following command which listed me all the file names containing my specified 'search text'.
findstr
can do recursive searches (/S) and supports some variant of regex syntax (/R).