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.)
"string" contains any "special" characters (i.e. doublequote, ampersand, pipe, greater or less than, caret, percent sign) these characters need to be escaped: a literal percent sign must be replaced by a double percent sign, a literal doublequote by 2 doublequotes, the rest must be preceded by a caret.FIND command is placed within a code block (i.e. in parenthesis) it is safest to escape parenthesis inside the text string with carets too.
So, with /C, FIND may be used for counting as well.
Use the FIND command to check if your HTML files have a closing tag for each opening tag:
C:\>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 )
FIND /C will only display the number of lines it finds with the search string specified; it does not display the number of occurrences of the search string!
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.
page last modified: 2016年09月19日; loaded in 0.0040 seconds