Searches for patterns of text in files using regular expressions.
Syntax
findstr [Options] [Parameter_1] [Parameter_2]
Options
/p | Skips files with non-printable characters. |
/b | Matches the pattern if at the beginning of a line. |
/o | Prints seek offset before each matching 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. |
/m | Prints only the file name if a file contains a match. |
/i | Specifies that the search is not to be case-sensitive. |
/n | Prints the line number before each line that matches. |
/x | Prints lines that match exactly. |
/v | Prints only lines that do not contain a match. |
Parameter_1
/f: file | Reads file list from the specified file. |
Parameter_2
/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. |
Findstr is capable of finding the exact text you are looking for in any ASCII file or files. Sometimes you have only part of the information you want to search. findstr has capability to search for patterns of text using regular expressions.
Regular Expressions
. | Wildcard: any character |
* | Repeat: zero or more occurrences of previous character or class |
^ | Line position: beginning of line |
$ | Line position: end of line |
[class] | Character class: any one character in set |
[^class] | Inverse class: any one character not in set |
[x–y] | Range: any characters within the specified range |
\x | Escape: literal use of metacharacter x |
\<xyz | Word position: beginning of word |
xyz\> | Word position: end of word |
Examples
Use spaces to separate multiple search strings. To search for “hello” or “here” in file xyz.txt
findstr “hello here” xyz.txt
To search every file in the current directory and all subdirectories that contained the word Table and ignores the case sensitive.
findstr /s /i Table *.*
To search all occurrences of lines that contain the word “HELLO, and include the line number where each occurrence is found.
findstr /b /n /c:” *HELLO” *.txt