Searches for patterns of text in files using regular expressions.
findstr [/b] [/e] [/l] [/r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/offline] [/g:file] [/f:file] [/c:string] [/d:dirlist] [/a:ColorAttribute] [strings] [[Drive:][Path] FileName [...]]
/b : Matches the pattern if at the beginning of a line.
/e : Matches the pattern if at the end of a line.
/l : Uses search strings literally.
/r : Uses search strings as regular expressions. Findstr interprets all metacharacters as regular expressions unless you use /l.
/s : Searches for matching files in the current directory and all subdirectories.
/i : Specifies that the search is not to be case-sensitive.
/x : Prints lines that match exactly.
/v : Prints only lines that do not contain a match.
/n : Prints the line number before each line that matches.
/m : Prints only the file name if a file contains a match.
/o : Prints seek offset before each matching line.
/p : Skips files with non-printable characters.
/offline : Processes files with offline attribute set.
/f:file : Reads file list from the specified file.
/c:string : Uses specified text as a literal search string.
/g:file : Gets search strings from the specified file.
/d:dirlist : Searches a comma-delimited list of directories.
/a:ColorAttribute : Specifies color attributes with two hexadecimal digits.
strings : Specified text to be searched for in FileName.
[Drive:][Path] FileName [...] : Specifies a file or files to search.
/? : Displays help at the command prompt.
Use spaces to separate multiple search strings unless the argument is prefixed with /c. To search for "hello" or "there" in file x.y, type:
findstr "hello there" x.y
To search for "hello there" in file x.y, type:
findstr /c:"hello there" x.y
To find all occurrences of the word "Windows" (with an initial capital W) in the file Proposal.txt, type the following:
findstr Windows proposal.txt
To search every file in the current directory and all subdirectories that contained the word Windows, regardless of the letter case, type the following:
findstr /s /i Windows *.*
To find all occurrences of lines that contain the word "FOR", preceded by any number of spaces, (as in a computer program loop), and to include the line number where each occurrence is found, type the following:
findstr /b /n /c:" *FOR" *.bas
If you want to search for several different items in the same set of files, create a text file that contains each search criterion on a new line. You can also list the exact files you want to search in a text file. To use the search criteria in the file Finddata.txt, search the files listed in Filelist.txt, and then store the results in the file Results.out, type the following:
findstr /g:finddata.txt /f:filelist.txt > results.out
Assume you wanted to find every file in the current directory and all subdirectories that contained the word computer, regardless of the letter case. To list every file containing the word computer, type the following:
findstr /s /i /m "\<computer\>" *.*
Now assume you want to find not only the word "computer," but also any other words that begin with the letters comp, such as "compliment" and "compete. " type the following:
findstr /s /i /m "\<comp.*" *.*