This problem can be solved with a very interesting trick !:
@echo off setlocal EnableDelayedExpansion (for /F "tokens=1,2 delims== " %%a in (CP.xml) do ( if "%%~b" neq "" set %%a=%%~b if /I "!flag!" equ "on" echo !name!& set flag= )) > Names.txt
EDIT : some explanation
The file has several lines, but the OP looks for lines that have an assignment form, for example:
name="RIVERTD" flag="on" name="BRETRED" flag="on" name="AMERAND" flag="off"
My program does NOT check any name, but it executes any line with a value after the equal sign as an assignment. Thus, when my program processes the previous lines, the result is equivalent to executing the following commands:
set name="RIVERTD" set flag="on" set name="BRETRED" set flag="on" set name="AMERAND" set flag="off"
After that, just check if the FLAG variable is set to "on"; if so, then the variable NAME has a target value because it was assigned on the previous line.
Antonio
source share