Now I have more time to write here.
If the variable set before the command SETLOCAL in the batch then:
Code: Select all
@echo off
set var1=Trebor68
setlocal enabledelayedexpansion
for /f "delims=" %%a in (test34.txt) do (
echo %%a
set var1=!var1!%%a
echo !var1!
echo.
)
endlocal
echo %var1%
Here the output:
Code: Select all
Anton
Trebor68Anton
Berta
Trebor68AntonBerta
Charly One
Trebor68AntonBertaCharly One
Dora
Trebor68AntonBertaCharly OneDora
Trebor68
And now combinated with the command FINDSTR.
For the search I use this file Test34a.txt:
Code: Select all
Anton
Smith, Anton
Berta
Berta Doe
Charly
One Two
Two Charly
Charly One
Iris One
Dora
Here the batch Test34a.bat:
Code: Select all
@echo off
setlocal enabledelayedexpansion
set var1=
for /f "delims=" %%a in (test34.txt) do (
echo.
set var1=%%a
echo Search string: !var1!
echo.
findstr /e "!var1!" Test34a.txt
)
echo.
echo ### End of search. ###
Here the output of the batch:
Code: Select all
Search string: Anton
Anton
Smith, Anton
Search string: Berta
Berta
Search string: Charly One
Charly
Two Charly
Charly One
Iris One
Search string: Dora
Dora
### End of search. ###
If you want to search only "Charly One" the use the command:
FINDSTR /E /C:"Charly One" Test34a.txtThe other strings with "Charly" or "One" at the end of the row will ignored.