The
find command will count the lines with the search argument. If a line has more than one occurrence of the search argument, it still counts for one.
Findstr does not do counting but allows for multiple search arguments and a limited form of regular expressions.
You can use VBScript which came with your Windows machine. The little demo script will prompt the user for the file name and the search argument. It can be tweaked to remove the prompts (which will probably gut the majority of the script).
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Do
WScript.StdOut.Write "Please enter file name: "
strFile = WScript.StdIn.ReadLine
If fso.FileExists(strFile) Then
Set objFile = fso.OpenTextFile(strFile, ForReading)
strCharacters = objFile.ReadAll
Exit Do
Else
WScript.StdOut.Write "Invalid file name ... Try Again" & vbCrLf
End If
Loop
Do
WScript.StdOut.Write "Please enter character string: "
strToCount = WScript.StdIn.ReadLine
If strToCount <> "" Then Exit Do
Loop
strTemp = Replace(LCase(strCharacters), LCase(strToCount), "")
WScript.Echo "Occurences of:", strToCount, "=", (Len(strCharacters) - Len(strTemp)) / Len(strToCount)
objFile.Close
Save the script with a
vbs extension and run only from the command prompt as:
cscript scriptname.vbsGood luck.