is there a difference between"DELIMS=" and "Tokens=*"

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

is there a difference between"DELIMS=" and "Tokens=*"

#1 Post by nnnmmm » 28 Dec 2021 02:37

AA=FOR /F "Tokens=*" %%V IN ('DIR') DO ECHO a
BB=FOR /F "DELIMS=" %%V IN ('DIR') DO ECHO a

CC=FOR /F "DELIMS=*&%^^&%" %%V IN ('DIR') DO ECHO a
DD=FOR /F "DELIMS=73k0s1j4" %%V IN ('DIR') DO ECHO a

i have been using BB for all my life, my logic was if you cant find the NULL string in a text file, then it gotta be the whole line, it has been working well and provenly well for me.
my logic for CC and DD was no one uses this kind of strange 73k0s1j4 delimers, so it gotta read the whole line. but CC didnt work.

i just found the meaning of AA, it means the whole line
could someone put words for BB CC DD for me? just few words would suffice. i dont understand(or remember) operators well, but i do well on the structure. now i am going to change all my working "DELIMS=" to "Tokens=*"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: is there a difference between"DELIMS=" and "Tokens=*"

#2 Post by aGerman » 28 Dec 2021 05:54

The meaning of AA is that it uses the whole line but strips leading default delimiters (spaces and/or tabs).
The meaning of BB is that it discards the default delimiters and thus, uses the whole line.
IIRC it was jeb who found out that AA is a little faster than BB and proposed to use both "tokens=* delims=".

CC and DD are bogus, but keep in mind that "delims=ABC" means you defined 3 deliters which are A and B and C.

Steffen

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: is there a difference between"DELIMS=" and "Tokens=*"

#3 Post by Compo » 28 Dec 2021 06:04

To begin with, your assessment of AA is incorrect. AA will pass each line which does not begin with a semicolon, ignoring any leading space and horizontal tab characters, to the DO command(s).

BB, on the other hand, will pass each line which does not begin with a semicolon, to the DO command(s).

The difference between the two is therefore that leading delimiters, (spaces and horizontal tabs are default delimiters), are stripped when using AA.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: is there a difference between"DELIMS=" and "Tokens=*"

#4 Post by aGerman » 28 Dec 2021 06:12

Haha, yeah.

Code: Select all

for /f delims^=^ eol^= %%V ...
... (without the usual surrounding quotes) is a way to get around the default eol issue.

Steffen

Post Reply