# Batch command to find number pof occurrences of a string in a file

## Issue

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?

## Solution

That seems very complicated when the `find` command does what you need (it sets `%ERRORLEVEL%` to `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
)
``````