|The Windows Command Processor's language is quite powerful, albeit a bit quirky. So I'll try and keep it simple.|
Type FINDSTR /? for full details of how to use FINDSTR.
The first line in your batch file should be:
The @ character suppresses the echoing of the current command on that line, and the echo off command supresses all subsequent echoing. The echo command in fact has two seprate uses: one for controlling the echoing of commands in a batch file, and another for printing a line to the console. Well, I did say it's quirky.
(Advanced question: how do you print out a line that says "off", if the command "echo off" doesn't actually print "off"? Well, I won't answer here, except to say this demonstrates that it is indeed quirky.)
If you don't want FINDSTR to print the matching line in the file, use the Command Processor's redirection feature to send the output to the null device (which uses the special file name "nul"):
FINDSTR "userstat=1" test123.txt > nul
Now how do you know if the search was successful, if the output was not shown? The FINDSTR utility returns a zero exit code (called errorlevel) if it finds the search term, and non-zero (positive value) otherwise. So, our next line in the batch file is:
if errorlevel 1 (
echo Search successful
) else (
echo Search failed
Note that the "else" part MUST be on the same line as the closing bracket, as shown above. The language is very line-oriented, not free-form like C or Java. Type IF /? for full details of how to use the IF command. But simply put, the above test if the errorlevel is 1 or above.
Type "%windir%\Help\ntcmds.chm" at the command prompt for full details of how to use commands in batch files.