Using FINDSTR to search text files

Posted: (EET/GMT+2)

 

If you need to locate text inside log files, configuration files, or source code, Windows includes a useful command-line utility called FINDSTR.

For example, the following command searches a log file for lines containing the word "error":

findstr "error" application.log

By default the search is case-sensitive. Use the /I option to ignore differences between uppercase and lowercase characters:

findstr /I "error" application.log

You can also search several files using wildcards:

findstr /I "error" *.log

The /S option searches matching files in the current directory and its subdirectories:

findstr /S /I "connection" *.log

FINDSTR also supports simple regular expressions, making it considerably more flexible than the older FIND command. This works particularly well together with command-line redirection. For example:

findstr /S /I "error" *.log > errors.txt

This searches the log files and saves the matching lines into errors.txt.

Type findstr /? to see the available search options.

This command when searching large collections of log or configuration files without opening them individually. A nice time saver!