I've got to believe this has been asked and answered before. But here is a simple batch script that can do the job.
::StringCount String File
::
:: Count the number of times that String appears in File.
:: The search is not case sensitive.
:: Enclosing quotes are not considered to be part of the string.
:: The string cannot contain =
::
@echo off
setlocal disableDelayedExpansion
set count=0
for /f usebackq^ delims^=^ eol^= %%A in (%2) do set "ln=%%A"&call :testLine %1
echo %count%
exit /b
:testLine
setlocal enableDelayedExpansion
:testLine2
if defined ln if "!ln:*%~1=!" neq "!ln!" (
set /a count+=1
set "ln=!ln:*%~1=!"
goto testLine2
)
endlocal & set /a count=%count%
exit /b
Command line usage would be
StringCount null yourFile.txt
This could become quite slow with large files.
I've written a hybrid JScript/batch utility called REPL.BAT that can make the job easy and should be quite fast. The utility performs a regex search and replace on lines read from stdin, and writes the result to stdout. It has a fair number of options, including options that simplify this task. The utility is pure script that will run on any modern Windows machine from XP onward. Full documentation is embedded within the script.
Here is how it could be used to solve your problem, assuming the search is case sensitive.
<yourFile.txt repl (null) \n$1\n ax | find /c "null"
If you want the search to be case insensitive
<yourFile.txt repl (null) \n$1\n aix | find /i /c "null"