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)?
This question is related to
windows
command-line
grep
Recursive search for import
word inside src
folder:
> findstr /s import .\src\*
Select-String
worked best for me. All the other options listed here, such as findstr
, didn't work with large files.
Here's an example:
select-string -pattern "<pattern>" -path "<path>"
note: This requires Powershell
for /f %G in ('dir *.cpp *.h /s/b') do ( find /i "what you search" "%G") >> out_file.txt
I just searched a text with following command which listed me all the file names containing my specified 'search text'.
C:\Users\ak47\Desktop\trunk>findstr /S /I /M /C:"search text" *.*
If you have Perl installed, you could use ack, available at http://beyondgrep.com/.
findstr /spin /c:"string" [files]
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:
I recommend a really great tool:
native unix utils:
Just unpack them and put that folder into your PATH environment variable and voila! :)
Works like a charm, and there are much more then just grep ;)
Source: Stackoverflow.com