Search for Text Inside a Group of Files

· Windows Scripts

If you need to search a group of files for a certain string of text, place the below script in a *.CMD file which resides in the same folder as all the files you would like to search. The results will output in a file called “Results.txt”.

REM Source:
REM Searches for strings in files.
REM FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file]
REM [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
REM strings [[drive:][path]filename[ ...]]
REM /B Matches pattern if at the beginning of a line.
REM /N Prints the line number before each line that matches.
REM * Wildcard: any character
ECHO Searches all files in the current directory for the text, "Error", at the
ECHO beginning of the line and saves where the text is located in a text file
ECHO called "Results.txt".
ECHO Warning: This file cannot be run on a UNC path. Please map the location
ECHO to a drive letter before executing this file.
findstr /N /B "Error" * > Results.txt
ECHO *** Search Process Completed ***
Start Notepad.exe Results.txt
author image

About Joseph Spurrier

I'm passionate about building solutions to automate tasks and improve efficiency. Tech guy. Traveler. Runner. Guitar player. Scotch and beer enthusiast. Keybase GitHub Gists LinkedIn Twitter

Share this post

Comments powered by Disqus