Click here for important information about

Solved Saving part of a file as a variable.

June 2, 2012 at 03:46:30
Specs: Windows 7
I want to open a file called text1.txt find the line that contains <id>example</id> and save example to the variable %ID%.

I know that I want to FIND </id> then use a FOR /f loop with tokens=2 delims=< to limit the temp variable down to "<id>example" then remove <id> somehow and save example to %ID%, but how?

Just to clarify example will be unknown it could be anything.

This is what I have atm:

for /f "tokens=2 delims=<" %%a in ('find "</id>" campaigns.xml') do set var=%%a
echo "%var%"

which outputs id>example
How do I make it work with more then 1 example?

Thanks in advance!

See More: Saving part of a file as a variable.

June 2, 2012 at 20:47:21
✔ Best Answer
Does this work for you?

@echo off
setlocal enabledelayedexpansion

for /f "tokens=3 delims=<>" %%a in ('find "</id>" test1.txt') do (
    set ID=%%a
    echo Var ID = !ID!

Please come back & tell us if your problem is resolved.

Report •

June 3, 2012 at 00:57:46
Post a few lines of the file.

Life is too important to be taken seriously.


Report •
Related Solutions

Ask Question