Fireball3 Posted March 13, 2014 Share Posted March 13, 2014 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! Quote Link to comment
cassiusdrow Posted March 13, 2014 Share Posted March 13, 2014 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 Quote Link to comment
S80_UK Posted March 13, 2014 Share Posted March 13, 2014 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. Quote Link to comment
DaleWilliams Posted March 13, 2014 Share Posted March 13, 2014 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. ) Quote Link to comment
Fireball3 Posted March 13, 2014 Author Share Posted March 13, 2014 FOR /F "tokens=* delims=;" %%i IN (%tmpfile%) DO CALL :BODY %%i Does not work. Cuts off after blank. Quote Link to comment
RobJ Posted March 14, 2014 Share Posted March 14, 2014 Did you try FOR /F "delims=^*" %%i IN (%tmpfile%) DO CALL :BODY %%i Quote Link to comment
Fireball3 Posted March 15, 2014 Author Share Posted March 15, 2014 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. Quote Link to comment
bonienl Posted March 15, 2014 Share Posted March 15, 2014 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 * Quote Link to comment
Fireball3 Posted March 17, 2014 Author Share Posted March 17, 2014 Great bonienl! This is working!!! thx Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.