March 13, 201412 yr Need help with this for loop - once more... This time it's a batch file in DOS console. I want to process a file line by line but it will always cut/break after a blank in the line. Lines without blanks work perfectly. My code at the moment: FOR /F "delims=*" %%i IN (%tmpfile%) DO CALL :BODY %%i I can't remember the countless possibilities of delims & tokens that I googled & tested. I don't believe it's that complicated but obviously I can't handle it. Appreciate your help!
March 13, 201412 yr I think it is not recognizing the "delims=*". I don't think an asterisk is supported and is it defaulting to a space. Change the asterisk to something that won't be in the data and add "tokens=*". Something like this: FOR /F "tokens=* delims=;" %%i IN (%tmpfile%) DO CALL :BODY %%i assuming there will not be a semicolon in the data. This site is a great reference for Windows/DOS batch commands: http://ss64.com/nt/for_f.html
March 13, 201412 yr This site is a great reference for Windows/DOS batch commands: http://ss64.com/nt/for_f.html Wow! I use FOR loops a bit, but there's plenty there that I was not aware of. Really useful stuff. Thanks for sharing.
March 13, 201412 yr This site is a great reference for Windows/DOS batch commands: http://ss64.com/nt/for_f.html Bookmarked that! (Still...my goal is to never need it. )
March 13, 201412 yr Author FOR /F "tokens=* delims=;" %%i IN (%tmpfile%) DO CALL :BODY %%i Does not work. Cuts off after blank.
March 15, 201412 yr Author Just tried: FOR /F "delims=^*" %%i IN (%tmpfile%) DO CALL :BODY %%i and FOR /F "tokens=* delims=^*" %%i IN (%tmpfile%) DO CALL :BODY %%i No joy.
March 15, 201412 yr You need to add quotes to the parameter. Do the following: FOR /F "delims=*" %%i IN (%tmpfile%) DO CALL :BODY "%%i" :BODY ECHO.%~1 GOTO :EOF Note the quotes when calling the subroutine BODY, and inside the subroutine %~1, which removes the quotes. This example assumes that the lines do NOT contain the character *
Archived
This topic is now archived and is closed to further replies.