Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delim by double quotes in a for in batch scripting

I have a file and I wish to use the for command to go through it. My issue is that I try to delim by double quotes character ["] and I have to escape it, so my for would look like this:

for /f tokens^=1^,2^,3^ delims^=^<^"^= %%a in ("%%i") do (

)

And I don't understand why is it that if I remove the last [^] from tokens tokens^=1^,2^,3**^** I get an error: that delims was unexpected.

Any suggestions on how can I delim by double quotes and not have to escape every other character?

like image 951
TBogdan Avatar asked Aug 31 '25 22:08

TBogdan


1 Answers

The problem is, that you use the options without enclosing quotes,
like in FOR /F "tokens=1,2 delims=[]" ....

But if you want to use a quote as a delim character, you can't use the enclosing quotes anymore.
And then nearly all characters must be escaped with a caret, as ,=;<space> are also standard token delimiters.

Even the spaces have to be escaped to create a single option token.
for /f tokens^=1^,2^,3 delims^=^<^"^= %%a
will be split into for - /f - tokens=1,2,3 - delims=<"=

But the /F expects exactly one or none option token.

like image 136
jeb Avatar answered Sep 03 '25 22:09

jeb