DOS FOR command

July 15, 2010 at 14:27:28
Specs: Windows XP
Im trying to use the DOS FOR command (within a BATCH file) to input lines from a file called configgeneral.txt. See below:
FOR /F "tokens=1,2* delims=;;" %%i IN (configgeneral.txt) DO @CALL :extract %%i %%j %%k

It was understanding from the doc that all subsequent words within a particular line will get thrown into the %%k variable due to the * at end of tokens 'flag'. But all I get is the 3rd word.

What am I doing wrong? Or is what I am asking not possible.


See More: DOS FOR command

Report •

July 15, 2010 at 14:52:03
Try tokens=1-2* etc..

Report •

July 15, 2010 at 17:32:12
the problem is in "extract", i imagine.
calling another batch file like this requires careful handling of spaces for the "replacable" parms:
f/e: if %%k is: this is var k
and you call extract like:
call :extract %%i %%j %%k
extract needs to make sure %3 gets all the rest of the words.
f/e, say i is ONE, j is TWO, and k is as above,if extract says:
echo %1 %2 %3
all you'll get is:
ONE TWO this
not: ONE TWO this is k
you can either put k into "", or you can use shift to get all the data:
call extract %%i %%j "%%k"
then strip the quotes in extract, or alternatively, in extract you can:
set one=%1
set two=%2
if "%1" equ "" goto :xit
set kay=%kay% %1
goto :loop
echo %one% %two% %kay%
this has the side-effect that all extra spaces will be filtered down to one space
(f/e, if %%k was: this       line
it will wind up as: this line

Report •

July 16, 2010 at 11:35:33
Can you post what the contents of "configgeneral.txt" looks like?

Report •

Related Solutions

November 16, 2010 at 12:58:01
Hello ace,

As you can probably tell. I have to abort trying to get that to work. However, it pleases me to no end to say that I finally figured out how to get "control" the way the FOR /F command inputs lines of text that contain spaces and commas.

My line inputs contain a city name in the middle of the string. The problem is that "Salt Lake City" would get stored into 3 variables instead of one.

Here is my solution:

FOR /F "tokens=*" %%a IN (output.txt) DO (

echo %%a >oneline.txt
CALL insert_new_stations.bat


In the insert_new_stations Batch file I write the contents of oneline.txt into a variable.

set /p currentline=<oneline.txt

From there a bunch of SET and IF commands do the rest.

Thanks for your help.

Report •

Ask Question