How can I read a comma delimited text file in a Windows batch file?

Posted by Sms on Super User See other posts from Super User or by Sms
Published on 2012-06-29T16:32:59Z Indexed on 2012/06/29 21:19 UTC
Read the original article Hit count: 149

Filed under:
|
|
|
|

I can get it to read the text file until it becomes a comma delimited text file.

I would like to read the two variables on each line and test each one with a If statement for another condition. Problem is I can't read the variables properly. Tried many things but here is what I will post. Timeouts are to see what's happening:

for /f "tokens=*" %%a in (TestText.txt) do (
timeout /t 1
echo %%a is the present variabe
timeout /t 2
if %%a=="One","1" echo Match for "One","1"
timeout /t 3
if %%a=="One""1" echo Match for "One","1"
timeout /t 4
if %%a=="One" echo Match for "One"
timeout /t 5
if %%a=="1" echo Match for "1"
timeout /t 6
)

TestText.txt

"One","1"
"Two","2"
"Three","3"
"Four","4"

OUTPUT:

"One","1" is the present variabe

© Super User or respective owner

Related posts about Windows

Related posts about command-line