| 1. |
Solve : How do I Parse data out of a file into a Variable?? |
|
Answer» This is one of the many attempts I have made to Parse data out of the file into a Variable. I think the problem here is that you are using a numeric loop variable, when it should be alphabetic Not quite. He wrote %4 not %%4. That's the problem. You can use %%a to %%z, %%A to %%Z and %%1 to %%9 as loop variables, although the number ones are not documented. Obviously you can't have as many implicit variables using "tokens=1,2,3" etc, if you choose to use numbers as the variable symbols in a loop. The problem is the number of % signs. There should be 2 in front of the variable letter or number in a batch file and 1 at the command prompt. CODE: [Select] SET INPUTVAR=%%4 ECHO INPUTVAR=%%4 Incidentally why not try this Code: [Select]FOR /F "delims=" %%4 IN (SPIMRF1.dat) DO SET INPUTVAR=%%4 ECHO INPUTVAR=%INPUTVAR% I tried several different variations using your posted suggestions. Either of the FOLLOWING TWO (2) pieces of code worked for me. FOR /F "delims=" %%P IN (SPIMRF1.dat) DO ( SET INPUTVAR=%%P ECHO INPUTVAR=%INPUTVAR% ) FOR /F "delims=" %%4 IN (SPIMRF1.dat) DO ( SET INPUTVAR=%%4 ECHO INPUTVAR=%INPUTVAR% ) Thank You very much for your help. Quote from: Dias de verano on June 04, 2008, 06:48:07 AM Not quite. He wrote %4 not %%4. That's the problem.DOH I didnt spot the single %4, he had %%4 on the FOR line I didnt know about %%num - all these years and theres still something new to learn !! Cheers Graham |
|