Discussion Locked

NT Command Shell: FOR command bug?

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Has anyone ever seen this one? Is it a bug?

The documentation for the FOR command states that the default delimiters are space and tab. In Win2K, this is true. However in NT 4.0 SP6, I cannot get FOR to recognize tabs.

i.e.
given a tab delimited text file (data.txt)
1 2 3
4 5 6

the command;
for /f "tokens=2" %i in (data.txt) do @echo %i

Win2K Output
2
5

NT Output...not a thing

Is there anyway to manually specify a tab using delim=? I tried "tokens=2 delims=\t" to no avail.

7 replies

by rorycarlin

This is just a guess. Have you tried "delims=" but instead of typing , press the tab button? Good luck.

by karlww

Thanks, but I already tried that. I also tried ALT+009 on the numeric keypad.

by joseph moore

I found this comment in the help for FOR:
"To use the FOR command in a batch program, specify %%variable instead of %variable Variable names are case sensitive, so %i is different from %I."

So, you need to change your variable, %i, to %%i. I tested it out and I got the good result!

So, change your FOR line to this:

for /f "tokens=2" %%i in (data.txt) do @echo %%i

It worked in both NT and 2000 for me.

Hope this helps.

by karlww

I was using the above on the command line itself (no batch file involved yet), so the single % is enough.

One question. Did you copy the "data.txt" above or did you make one? Go to Notepad (or whatever) and type, 1, press TAB, 2, press TAB, 3 press ENTER, 4, press TAB, 5, press TAB, 6. Now save the file and execute the command. You should get the same failure I did under NT.

This discussion is closed to new replies.