I need to find how many times a string exists in a file. If it is not equal to 0 then return error status:
set "file=C:\output\summary.txt" for /f %%F in (findstr /I "FAIL" %file% | find /I /C "FAIL") do ( set count=%%F ) if count neq 0 exit /B 1 exit /B 0
But when I run the batch I get error:
| was unexpected at this time.
How can I fix the issue and achieve the expected?
That seems very complicated when the
find command does what you need (it sets
1 if it doesn’t find the string):
set "file=C:\output\summary.txt" find /C "FAIL" %file% if "%ERRORLEVEL%"=="0" ( exit /B 1 ) else ( exit /B 0 )
Answered By – thebjorn