0

I am new to writing batch files. I am trying to do the following .

Read line by line from file called list.txt which has two tokens which are space seperated and in the next for loop i am tokenizing and sending these tokens as parameters to another script.

FOR /F %%i IN (C:\list.txt) DO

FOR /F "tokens=1,2 delims= " %%A IN (%%i) DO   
winscp.com /script=C:\myscript1.txt /parameter %%A  C:\%%B

But I am getting the following error. Do was un expected at this time.

Can some one explain what am I missing.

Thanks

javaMan
  • 6,352
  • 20
  • 67
  • 94

2 Answers2

2

Batch files aren't free form and plenty of whitespace is significant. Such as in this case where you could write it all in one line but you cannot spread it out over several lines.

Another option is to explicitly use blocks:

FOR /F %%i IN (C:\list.txt) DO (
  FOR /F "tokens=1,2 delims= " %%A IN (%%i) DO (
    winscp.com /script=C:\myscript1.txt /parameter %%A  C:\%%B
  )
)
Joey
  • 344,408
  • 85
  • 689
  • 683
  • I tried putting everything in single line. Even it didnt work – javaMan Mar 30 '12 at 20:00
  • Hi Joey, I am sorry. It worked. But I am getting different error. In my file I have only one line "good boy" and I changed the body inside the second for loop as echo %%B. I am getting something like good is not recognized as command – javaMan Mar 30 '12 at 20:16
1

Independently of the already solved problem, you may achieve the token separation in the same FOR that read the file. Also, FOR command have spaces as default separators, so delims= " is not needed. That is:

FOR /F "tokens=1,2" %%A IN (C:\list.txt) DO  (
   winscp.com /script=C:\myscript1.txt /parameter %%A  C:\%%B
)
Aacini
  • 65,180
  • 12
  • 72
  • 108