Site Navigation

Apr 19, 2012

Windows Equivalent of Grep

Microsoft Logo
I have been looking for a Windows equivalent for the Unix grep utility for some time. Only recently have I find the solution, it seems Google search has been leading me astray! :)

The command is:

and it has been available since Windows XP.

For example if I wanted to search all the .java files in the current directory and all sub-directories for "Class" I would use the following command.
findstr /s /n "Class" *.java

The /s switch searches all sub-directories. The /n switch displays the line number where the match was found. If a match is found, the file name and path is also displayed.

As another example, if I wanted to do a case insensitive search I would use:
findstr /s /i /n "Class" *.java

The command also supports regular expressions so you can make your searches as complex as you want.
Post a Comment

Favorite Links Feed