DOS SHELL for /F in file


Fireball3

Recommended Posts

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!

Link to comment

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

Link to comment

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 *

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.