Basic Grep in Windows

24 August 2012

When developing on Windows machines I often find myself needing to search through a group of files looking for a given string. The standard tool for the job is grep, and while it can be installed on Windows it isn’t installed by default. Instead I’ve found that the findstr command performs 90% of what I need.


For example the following will look through the current directory and all subdirectories for the string thetexttofind

findstr -s "thetexttofind" *.*

You can also search for regular expressions. The following example will search for all lines in a file that start with the string foo

findstr -s "^foo.*" *.*


If you prefer Powershell for Windows scripting, these commands work there as well.