Search word inside .txt file using batch file

I'm looking for a batch file to search through a txt file and if it finds the word "Failed" then EXIT 1. Any help?

0


a source to share


3 answers


here is something similar to what Garrett said, but you can run it as a background process, for example displaying some other information on stdout:



@echo off
@start /wait FIND /C /I "SearchPhrase" path-to-your-file\filename.abc
IF ERRORLEVEL 1 (do-something)

      

+1


a source


It might get you started ...

type file.txt | find "Failed"

      



If it returns something, you set the ERRORLEVEL variable to 1.

Hope it helps dude!

+1


a source


FindStr "Failed" YourFile.Txt >Nul:
If ErrorLevel 1  
  ... then it is NOT found (findstr returns 0 if found

      

0


a source







All Articles