I am having a problem figuring out how to populate a file with variables and then running a loop to print series of lines.
Here are the codes:
Batch 1:
@echo off
:: This batch read a file and copy all lines containing that word into a new
file in an ordered list. (This works just fine)
findstr /C:"wordA" OLD.txt >> list_of_variables.txt
for /f "delims=" %%x in (list_of_variables.txt) do set string=%%x & call dp2.bat %string%
The result is something like this
wordA 1111 wordb
wordA 1112 wordb
wordA 1113 wordb
wordA 555 wordb
Batch 2:
@echo off
cls
:: This batch is supposed to get the variable %string% and look in a different file (old.txt) and copy a block of 10 lines below the matching string.
setlocal enabledelayedexpansion
set string=%string%
for /f "tokens=*" %%1 in (OLD.txt) do (
if !flag! equ 1 (
echo !string! %%1 >> output.txt
set /a count+=1
if !count! gtr 10 goto endit
)
if /i "%%1" equ "!string!" (set flag=1)
)
echo "%string%" not found check spellings and input file.
exit /b
:endit
type output.txt
The intended result will be something like:
|-same as string| | read form old.txt|
wordA 1111 wordb wordc word worde worf
wordA 1111 wordb wordg worh wordi worj
Here is the deal:
If I use them separately they both work fine, but when I try to make them work together it does not work. The batch 2 with worda
set as set string=worda
works like a charm, so I know it is correct but when I pass the variable from the batch 1, it does not print anything in the output.txt file.
Other solution is to call the 2 loops in the same batch file but I haven't been able to figure it out.
Any assistance or guidance will be highly appreciated.
Jonathan.