Yes, tokens=*
and delims=
are different:
delims=
returns the whole line unedited;
tokens=*
returns the line with any leading delimiters (SPACE and TAB as per default) removed;
tokens=* delims=
behaves exactly the same way as delims=
;
Note that empty lines are always skipped. Also lines that begin with ;
are ignored as that character is the default eol
.
If tokens=*
is specified and a line contains delimiters only, the for /F
loop iterates and the meta variable returns an empty string. As soon as any token number is provided (like tokens=3
, tokens=1,3
, tokens=2-3
, tokens=2*
, etc.), delimiter-only lines are skipped.
However, a line that contains one or more delimiters plus the eol
character plus an arbitrary string are ignored even when tokens=*
is provided.
For evidence I did some tests, using the following text file sample.txt
(note that the 2nd line is empty, the 4th line contains four SPACEs; click on the edit button below this answer and view the raw text):
text_without_delimiters
text with delimiters
text with leading and trailing delimiters
; comment text
; comment text with leading delimiters
text plus ; comment text
And here is what I did on the console together with the respective return strings:
>>> for /F %I in (sample.txt) do @echo "%I"
"text_without_delimiters"
"text"
"text"
"text"
>>> for /F "tokens=*" %I in (sample.txt) do @echo "%I"
"text_without_delimiters"
"text with delimiters"
""
"text with leading and trailing delimiters "
"text plus ; comment text"
>>> for /F "delims=" %I in (sample.txt) do @echo "%I"
"text_without_delimiters"
"text with delimiters"
" "
" text with leading and trailing delimiters "
" ; comment text with leading delimiters"
"text plus ; comment text"
>>> for /F "tokens=* delims=" %I in (sample.txt) do @echo "%I"
"text_without_delimiters"
"text with delimiters"
" "
" text with leading and trailing delimiters "
" ; comment text with leading delimiters"
"text plus ; comment text"
>>> for /F "tokens=3" %I in (sample.txt) do @echo "%I"
"delimiters"
"leading"
";"
>>> for /F "tokens=1,3" %I in (sample.txt) do @echo "%I" "%J"
"text_without_delimiters" ""
"text" "delimiters"
"text" "leading"
"text" ";"
>>> for /F "tokens=2-3" %I in (sample.txt) do @echo "%I" "%J"
"with" "delimiters"
"with" "leading"
"plus" ";"
>>> for /F "tokens=2*" %I in (sample.txt) do @echo "%I" "%J"
"with" "delimiters"
"with" "leading and trailing delimiters "
"plus" "; comment text"
So the only really strange and unexpected output is the line ""
with the tokens=*
option alone.