Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a simple batch file (forbat.bat), with the following content:

FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") DO @echo Date paid %%G

When I run this batch file, I can get the result.

Now, I want to break the lines into a few lines, to make them easier to read. This is what I did:

FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") 
 DO 
 @echo Date paid %%G 

This time, I got a "The syntax of the command is incorrect" error.

It seems that I must have missed some semicolons and slashes when introducing the line breaks. How to make the above code work in windows batch file?

share|improve this question
add comment

3 Answers

As Dennis said, you can use the caret, but you mustn't have spaces at the start of the following lines:

FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^ 
DO ^ 
echo Date paid %%G

Otherwise it doesn't work. However, if you are willing to leave the DO in the original line, you can use parentheses to delimit a block

FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") DO (
   @echo Date paid %%G
)
share|improve this answer
add comment

You need a carat "^" for a line continuation character at the end of each line where commands are split.

FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") ^
DO ^
echo Date paid %%G
share|improve this answer
    
It doesn't seem to work: I got a DO ^ thing printed out and that was it. –  Graviton Jan 11 '10 at 7:10
    
It doesn't like any indentation or the @ sign apparently. –  Dennis Williamson Jan 11 '10 at 7:36
add comment
up vote 0 down vote accepted

This is the correct syntax, that works on my Windows XP machine:

FOR /F "tokens=4 delims=," %%G IN ("deposit,$4500,123.4,12-AUG-09") DO (  
@echo Date paid %%G 
@echo hiforbat ) 

This is the output:

Date paid 12-AUG-09
hi
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.