user62958
user62958

Reputation: 4929

Search for a word inside .txt file using batch file

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

Upvotes: 0

Views: 15679

Answers (3)

Vuk
Vuk

Reputation: 1235

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

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

Upvotes: 1

Stu
Stu

Reputation: 15769

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

Upvotes: 0

Garrett
Garrett

Reputation: 1790

This might get you started...

type file.txt | find "Failed"

If that returns anything, you set the ERRORLEVEL variable to 1.

Hope that helps dude!

Upvotes: 1

Related Questions