I want to parse a string with FOR /F where the delimiter character is the double-quote character (i.e. ")
for example, the contentes of C:\temp.out is:
name = "Joe"
I want to use something like
FOR /F "tokens=1,2 delims=^"" %%I in (temp.out) do @echo =%%J
and I'd like it to print
Joe
But I can't get FOR to treat " as a delimiter. I tried to escape it with ^", but no luck.
Any ideas?
Thanks.
How do I specify the " character as a delimiter in FOR
Moderator: DosItHelp
Hi melliott,
I can see your problem, but can't solve it a "nice" way, but I can solve it in two steps.
First reading a complete line,
then replacing all " to another "unsued" character (I use #),
then splitting it with another FOR /F.
bye
Jan Erik
I can see your problem, but can't solve it a "nice" way, but I can solve it in two steps.
First reading a complete line,
then replacing all " to another "unsued" character (I use #),
then splitting it with another FOR /F.
Code: Select all
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL ENABLEEXTENSIONS
FOR /F "tokens=*" %%I in (temp.out) do (
set par=%%I
set por=!par:"=#!
for /F "tokens=1,2 delims=#" %%J in ("!por!") DO echo %%K
)
bye
Jan Erik
If the parsing allows '=' and ' ' as delimiters then you could use the tilde to remove quotes from the resulting string in %%J. I.e.:
Code: Select all
FOR /F "tokens=1,2 delims== " %%I in (temp.out) do @echo.%%~J