Use the FIND command to search for a specific string in a file or files and send the specified lines to your output device.

(Windows NT 4 Resource Kit owners or Windows 2000 users 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.
  "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.

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


Combine it with FOR to create this small OS/2 or NT "batch file", which should be called with an HTML file name as its only parameter:

	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) The line of code displayed above should be read and typed as one single command line.
(2) In the example described here, 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!
(3) In DOS batch files, no line should ever exceed 127 characters.


In MS-DOS 6 and up FIND returns an errorlevel of 1 or higher if the search string wasn't found.
IsDev.bat is an example of a batch file depending on this feature.



page last uploaded: 1 May 2013, 12:46