Use the FIND command to search for a specific string in a file or files and send the specified lines to your output device.
(you may prefer FINDSTR, a much more powerful version of FIND, which even supports regular expressions.)
|FIND [/V or /C][/I][/N] "string" [drive:][path]filename|
|/V||Displays all lines not containing the string specified.|
|/C||Displays the count of lines containing the string.|
|/I||Ignores the case of characters when searching for the string.|
|/N||Displays the line numbers with the displayed lines.|
|/OFF[LINE]||Do not skip files with offline attribute set (only available in Windows XP and later versions).|
|"string"||Specifies the text string to find.|
|drive:\path||Specifies the location of the file or files to search.|
|filename||Specifies the name of the file to be searched.|
|If a path is not specified, FIND searches the text typed at the prompt or piped from another command.|
FIND may be used for counting as well.
FIND command to check if your HTML files have a closing tag for each opening tag:
FIND /C /I "<TD" example.html
---------- example.html: 20 C:\>
FIND /C /I "</TD" example.html
---------- example.html: 20 C:\>_
Combine it with
FOR to create this small batch file (for Windows NT or later, or OS/2), which should be called with an HTML file name as its only argument:
@ECHO OFF FOR %%A IN (A CODE FONT H1 H2 H3 P PRE TABLE TD TH TR) DO ( ECHO.%%A FIND /C /I "<%%A" %1 ECHO./%%A FIND /C /I "</%%A" %1 )
|Notes:||1:||In this example
|2:||In "true" DOS batch files, no line should ever exceed 127 characters.|
FIND returns an errorlevel 1 if the search string wasn't found (as of MS-DOS 6).
IsDev.bat is an example of a batch file depending on this feature.
Thanks to Robert Cruz, who provided me with details on escaping doublequotes in
FIND's search string.
He also provided this link to Microsoft's FIND command web page.