Can we use FINDSTR
Vis,
( Code has not been fully tested but my price is right.)
REM This generic batch string counter should work for most files and strings
Rem replace * with double quote symbol
Rem Usage: cnt812.bat string file.txt
REM Usage: cnt812.bat the id.txt
C:test>type cnt812.bat
@echo off
set /a c=0
setlocal enabledelayedexpansion
for /f *tokens=1-26* %%a in (%2) do (
if *%%a*==*%1* set /a c=!c! + 1
if *%%b*==*%1* set /a c=!c! + 1
if *%%c*==*%1* set /a c=!c! + 1
if *%%d*==*%1* set /a c=!c! + 1
if *%%e*==*%1* set /a c=!c! + 1
if *%%f*==*%1* set /a c=!c! + 1
if *%%g*==*%1* set /a c=!c! + 1
if *%%h*==*%1* set /a c=!c! + 1
if *%%i*==*%1* set /a c=!c! + 1
if *%%j*==*%1* set /a c=!c! + 1
if *%%k*==*%1* set /a c=!c! + 1
if *%%l*==*%1* set /a c=!c! + 1
if *%%m*==*%1* set /a c=!c! + 1
if *%%n*==*%1* set /a c=!c! + 1
if *%%0*==*%1* set /a c=!c! + 1
if *%%p*==*%1* set /a c=!c! + 1
if *%%q*==*%1* set /a c=!c! + 1
if *%%r*==*%1* set /a c=!c! + 1
if *%%s*==*%1* set /a c=!c! + 1
if *%%t*==*%1* set /a c=!c! + 1
if *%%u*==*%1* set /a c=!c! + 1
if *%%v*==*%1* set /a c=!c! + 1
if *%%w*==*%1* set /a c=!c! + 1
if *%%x*==*%1* set /a c=!c! + 1
if *%%y*==*%1* set /a c=!c! + 1
if *%%z*==*%1* set /a c=!c! + 1
)
echo count=%c%
echo.
echo Display %2
echo.
type %2
Output:
C:test>cnt812.bat the id.txt
count=10
Display id.txt
the
the
the
the
the the the
the the the
C:test>