Empty token in FOR /F

Hi there,

What did i do wrong, so:

@ECHO OFF
ECHO 1 1,,3 3>1.txt
FOR /F "tokens=1-3 delims=," %%A in (1.txt) DO ECHO "%%A"_"%%B"_"%%C"
PAUSE
EXIT

Open in new window

Results to:
"1 1"_"3 3 "_""

Expected result:
"1 1"_""_"3 3"

Cheers,
Rene
LVL 10
ReneGeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
3 is being treated as part of > by the looks so 1.txt not even getting created for me.

@ECHO OFF
(ECHO 1 1,,3 3)>1.txt
FOR /F "tokens=1-3 delims=," %%A in (1.txt) DO ECHO "%%A"_"%%B"_"%%C"
PAUSE

Open in new window


Steve
0
Steve KnightIT ConsultancyCommented:
Oh sorry I see what you mean.  consecutive delimeters count as one.  Only thing you could do I suppose is:

@ECHO OFF
setlocal enabledelayedexpansion

(ECHO 1 1,,3 3)>1.txt
For /F "tokens=*" %%X in (1.txt) do (
  Set Line=%%X
  Set Line=!line:,,=,"",!
  FOR /F "tokens=1-3 delims=," %%A in ('echo !line!') DO ECHO "%%~A"_"%%~B"_"%%~C"
)
PAUSE

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve KnightIT ConsultancyCommented:
Or indeed maybe this:

@ECHO OFF
setlocal enabledelayedexpansion

(ECHO 1 1,,,4 4,5,6 6)>1.txt
For /F "tokens=*" %%X in (1.txt) do (
  Set Line=%%X
  Set Line=!line:,=","!
  echo "!line!"
)
PAUSE
0
ReneGeAuthor Commented:
Hey Steve!!

Thanks for being so obvious that "" is required :)

I think I get it, buuut... do you have another example?  Naaaaa just kidding bro!!!

Cheers,
Rene
0
Steve KnightIT ConsultancyCommented:
haha, was late... always bit of a pain that it treats multiple delimeters as one.... until they are spaces and you want to get the next token etc..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.