Question

I'm trying to search in a logfile (test1.txt) for the error message. In the message there is the word 'error'. So if I found that word, I will pick that sentence and set it in a variable, so I can add all the error lines in one variable. So I can use them to manipulate them. But how can I fill the variable, I did this, but it takes ages without result:

for /F "delims=" %%a in ('findstr /r /c:"^*.error.*" test1.txt') do set errorcode=%%a
echo %errorcode%
Was it helpful?

Solution

Your SET will overwrite each time the variable, you doesn't append the texts.
Btw I see two problems, you use errorcode, but this is also the name of the internal errorlevel.
The second problem can be the line limit at 8191 characters. A variable can not hold more characters.

setlocal EnableDelayedExpansion
set "errortext="
for /F "delims=" %%a in ('findstr /r /c:"^*.error.*" test1.txt') do (
    set "errortext=!errortext! %%a"
 )
echo !errortext!
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top