Use the FINDSTR command to search for a specific string in a file or files and send the specified lines to your output device.
FINDSTR was introduced in the Windows NT 4 Resource Kit and is now a native command in Windows 2000 and later.
FINDSTR
Searches for strings in files.
Use spaces to separate multiple search strings unless the argument is prefixed with /C.
For example FINDSTR "hello there" x.y searches for "hello" or "there" in file x.y.
FINDSTR /C:"hello there" x.y searches for "hello there" in file x.y.
To learn more about regular expressions read Mastering Regular Expressions (2nd Edition) by Jeffrey E.F. Friedl.
More titles on regular expressions can be found here.
FINDSTR may not be available on every system your batch file targets: though native in Windows 2000 and later, it has to be bought and installed separately on Windows NT 4 systems.
The following code snippet can be used to detect if FINDSTR is available:
FINDSTR /? >NUL 2>&1 IF ERRORLEVEL 1 ECHO FINDSTR not available!
or:
FINDSTR /? >NUL 2>&1 || ECHO FINDSTR not available!
This trick has been used in ReadReg.bat to decide if FINDSTR or EGREP should be used.
ROBOCOPY D:\sourcedir E:\targetdir /NP /MIR | RXGREP "\s+\d+\s+D:\\sourcedir\\[^\n\r]*\r\n([^\n\r\\]+\r\n)+" /I125 D:\sourcedir\subdir\ New File 342 brandnewfile.ext Newer 4.06m updatedfile.ext *EXTRA File 2.40m deletedfile.extHover your mouse over the regular expression or the output to highlight the "components" of the regular expression and their matches.
"((\s+\d+\s+D:\\sourcedir\\[^\r\n]*\r\n+([^\r\n\\]+\r\n+)+)|\s+Total\s+[^\r\n]+\r\n+(\s+(Dirs|Files|Bytes|Times)\s:\s+[^\r\n]+\r\n+)+)"page last modified: 2016年09月19日; loaded in 0.0021 seconds