1

I have this text file:

NAME=MDF
VERSION=20140710
RELEASE_LIBRARY_DIRS=
DEBUG_LIBRARY_DIRS=
RELEASE_LIBRARIES=
DEBUG_LIBRARIES=
RELEASE_DEFINITIONS=
DEBUG_DEFINITIONS=

I want to parse out the version number and save it in a variable. Ive never done anything like this in batch and the for loops are confusing me. This is what I have so far. Mostly from another source.

@ECHO off

SET /P MYVAR=<MDFinfo.txt
ECHO MYVAR=%MYVAR%
FOR /f "tokens=1,2* delims==" %%I IN ( "%MYVAR%" ) DO (
    ECHO LINE=%%I
    ECHO RESULT=%%J
    SET /A RESULT=%%I
)
ECHO The number is: %RESULT%
pause

This is Echoing the NAME and MDF but not the line I want. Also when result is printed at the end it comes out to be 0. Can someone please explain to me how the tokens and delims work? Also how can I pull out the version number. The text file cannot be changed.

Thanks

Kierchon
  • 2,271
  • 1
  • 19
  • 24
  • possible duplicate of [Parsing string in batch file](http://stackoverflow.com/questions/12629775/parsing-string-in-batch-file) – VoteCoffee Sep 29 '14 at 19:44
  • Thats for parsing a string. I cant figure out how to get more than one line @VoteCoffee – Kierchon Sep 29 '14 at 19:56
  • How about letting us in on some secrets? Like which line is the "line I want" and what you expect to get out, for instance. Do you want the actual line, or do you want the line number, or both or what? – Magoo Sep 29 '14 at 23:19
  • @Magoo I wanted to pull out the version number. I dont want the entire line just the "20140710". I got close using the answer below but I think the find is messing me up. Let me know if you have any ideas. – Kierchon Sep 30 '14 at 15:04

1 Answers1

2
@echo off

FOR /f "delims=" %%I IN ( 'find /i "version=" ^< "c:\textfile.txt" ' ) DO (
   set "%%I"
)
echo %version%

Not tested

foxidrive
  • 40,353
  • 10
  • 53
  • 68
npocmaka
  • 55,367
  • 18
  • 148
  • 187