EDD
EDD

Reputation: 45

Finding Strings on the text file - Batch file

I would like to ask if how can I find strings (3 or 5 words) on the text file with conditions. If the strings was found then a certain variable will become equal to 1.

Scenario

I have a batch file will run every 12:01 AM. This batch file have multiple commands inside. Please see below:

  1. Tail logger
  2. Log checker
  3. Restarter

Tail logger - This was the first function will run on the batch file. It will tail log the server and put the logs on a server.log and create another log file that will have the last 2 lines of the logs (temp.log)

Log Checker - After the tail logger, This function will run and will find the a certain words on the temp.log.

Example:

This will find a strings "The task complete" if the checker find this it will make a variable from set X=0 to set X=1.

Thanks.

Upvotes: 0

Views: 1829

Answers (1)

Magoo
Magoo

Reputation: 80213

findstr /? from the prompt will guide you.

`findstr /L /c:"The task complete" "logfilename" >nul

will set errorlevel to 0 if found 1 otherwise (strictly not-0 otherwise, as "filemissing" produces errorlevel=2, I believe)

Upvotes: 1

Related Questions