Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch Test if result of a findstr command is empty

Tags:

batch-file

I want to make a batch which search a line in a text file and return true if the line is found or false if it's not.

This how I finf the line, but I don't know how to test it:

findstr /r /c:"^Process Status.*no errors, no warnings$" myfile.log

Can you help me on this please?

Thanks

like image 566
user2269756 Avatar asked Dec 21 '25 15:12

user2269756


1 Answers

findstr /r /c:"^Process Status.*no errors, no warnings$" myfile.log > nul
if errorlevel 1 (
    echo The line was not found
) else (
    echo The line was found
)

Check if the command sets errorlevel. If it is set, the text was not found.

like image 104
MC ND Avatar answered Dec 24 '25 10:12

MC ND



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!