FINDSTR

(from Find Strings)

Searches for strings in files. This command is an extension of the FINDFIND command, except for the line counting feature.

FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file] [/C:"string"] [/G:file] [/D:dir list] [/A:attr_col] [/OFF[LINE]] "strings" [[drive:][path]filename [...]]

Where:

  • /B - Searches for the element at the beginning of the line.
  • /E - Searches for the element at the end of the line.
  • /L - Uses search strings literally.
  • /R - Uses search strings as regular expressions (see below).
  • /S - Searches files in the current directory and all subdirectories.
  • /I - Specifies that the search should not be case-sensitive.
  • /X - Prints the lines that match exactly.
  • /V - Prints only lines that contain no matches.
  • /N - Prints the corresponding line numbers.
  • /M - Prints only the filename if it contains a match.
  • /O - Prints the character offset before each match.
  • /P - Ignores files with non-printable characters.
  • /OFF[LINE] - Does not ignore files that have the offline attribute set.
  • /A:attr_col - Specifies the color attribute with two hexadecimal digits (see COLORCOLOR).
  • /F:file - Reads the file list from the specified file.
  • /C:"string" - Uses the specified string for a literal search.
  • /G:file - Reads the search strings to use from the specified file.
  • /D:dir list - Searches for a semicolon (;)-delimited list of directories.
  • "strings" - Specifies the words to search for.
  • [drive:][path]filename - Specifies the files to search for.

If spaces are used when specifying strings without /C: in front, a search is made for each string, otherwise, if /C: is used, a search is made for a single string of multiple words (see examples).

Regular expression reference:

  • . - Shows all strings.
  • * - Repeats zero or more occurrences of the previous character or class.
  • $ - Displays the last string.
  • [class] - Any character from the set (in square brackets [ ], each separated from another by a comma ,).
  • [^class] - Any character not in the set (without square brackets [ ], each separated by a comma ,).
  • [x-y] - Any character in the specified range.
  • \x - Literal use of the x character (escaping).
  • \<xyz - Start of word.
  • xyz\> - End of word.

Examples:

1. Search for any string containing the words handsome coconut (without being separated) in the file C:\Documents and Settings\salted capers.txt ignoring uppercase and lowercase:

findstr /i /c:"handsome coconut" "C:\Documents and Settings\salted capers.txt"

 

2. Search for the words Damn, the and shovel in the file C:\bucket.doc with the colors white for the text and dark blue for the background:

findstr /a:1f "Damn the shovel" "C:\bucket.doc"

 

3. Search for any string not containing the characters c, d, t, v, and z in the C:\Wow!!.pdf file:

findstr /r ^c,d,t,v,z "C:\Wow!!.pdf"

Comments