0

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.

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

3 Comments

check like this: if ERRORLEVEL 1 (echo ERRORLEVEL is 1 or higher) & (goto :end)
I have rarely seen FINDSTR return anything other than 0 or 1. I've tested the missing file case, and many others. The only other return value I have seen is 255 when the regex contains more than 15 character class terms (a very nasty error that requires user interaction to dismiss a pop-up window).
@dbenham : conflicting options, eg FINDSTR /l /r "abc" "%filename1%"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.