Command library / findstr
findstr
Search for text in files or piped output (the Windows grep)
Finds lines that contain a text. By default a search string with spaces is treated as SEVERAL words joined by OR; to search for an exact phrase use /c:"the phrase". It reads files, or the output of another command through a pipe.
Practice findstrUsage
Options and flags
stringstext to look for (or the files when /c: is used)
filesfiles to search (omit to read piped input)
/iignore upper/lower case
/nprint the line number before each match
/vinvert: print lines that do NOT match
/ssearch subdirectories too
/c:PHRASEsearch for the exact phrase (spaces included)
Examples
findstr /i failed security.logLines containing 'failed' in any case.
findstr /i /n failed security.logSame, with line numbers.
findstr /i /v debug app.logEverything except debug lines.
findstr /c:"logon failure" security.logThe exact phrase, not 'logon' OR 'failure'.
Common mistakes
Without /c: the space means OR — you would also get lines containing only 'logon' or only 'failure'.