One way around it is first to replace the " characters with a more
delims-tolerant character. Somewhat along the lines of e.g.
34} How can I remove the quote characters from a line?
http://www.netikka.net/tsneti/info/tscmd034.htm
All the best, Timo
--
Prof. (emer.) Timo Salmi, Vaasa, Finland
http://www.netikka.net/tsneti/homepage.php
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php
You can optionally shows us some of the text and explain what you need to parse. There are some ways to get around this, depending on the text layout.
--
Regards,
Mic
thanks
I think first solution of your link is good for me, but I have a
problem,
set command does not work in for /f..... do ( ) why?
for example, below line print "test" not "test2"
@echo off
set VERSION_SRC=XilinxPrj\Embed_proc_AXI\pcores\version_v1_00_a\hdl
\vhdl\user_logic.vhd
set line_=test
for /D %%d in ( ???_? ) do (
for /f "tokens=5-12 delims=;_X " %%i in ('findstr /I /R /
c:"hw_version_brch.*<=.*" %%d\%VERSION_SRC%') do (
set line_=test2
echo. %line_%
)
)
@echo on
You have to declare:
setlocal ENABLEDELAYEDEXPANSION
and use:
echo. !line_!
instead of
echo. %line_%
L.
echo( should be prefered against echo., as it is ~10 times faster and
more robust.
To use a quote character as a delim character in a FOR /F loop is
posible,
it only looks a bit ugly.
setlocal EnableDelayedExpansion
set "var=one"two"three"
FOR /f tokens^=1-3^ delims^=^" %%a in ("!var!") do echo %%a--%%b--%%c
found by pieh-ejdsch last month http://www.administrator.de/index.php?content=172844
(german batch forum)
jeb
FOR /f tokens^=1-3^ delims^=^" %%a in ("!var!") do echo %%a--%%b--%%c
????
I'm not sure whether I'm more astonished that this works or that someone
would attempt to use such "obviously-broken" syntax.
(but the escaped-space after the "3" is redundant. If the superfluous space
exists, it must be escaped however...)
The space behind the 3 may be superfluous, but normally you add it to
the options like
FOR /F "tokens=1-3 delims=X" looks better than FOR /F
"tokens=1-3delims=X"
The syntax is a bit compliacated as all the standard delims for a
batch line are active there ;,=<space> and <tab>
Obviously the special characters like ^&|<> have to be escaped
Ther percent must always be escaped, even if it is in a `normal`
quoted option string.
I build a similar string for disabling the EOL character (which can't
be empty), by setting it to the line feed character.
for /f ^"tokens^=1-3^ eol^=^
^" %%a in (myFile) do ...
The line break is necessary for inserting the LF.
But even if I used the "escaping" syntax I never got the idea to
remove the quotes completly, and with the surrounding quotes you can't
set the delims to the quote character.
jeb
> thanks
> I think first solution of your link is good for me, ...
Good. You might also find the following of some interest
http://www.netikka.net/tsneti/info/tscmd072.htm#vbs
All the best, Timo
--
Yes, but now it's outdated.
With using directly the quotes as delims the workaround is no longer
necessary
jeb
Yes, a time ago I tested it with FOR /L, the following lines are doing
excactly the same,
as only the delims are necessary while parsing, the rest will be
ignored
FOR /L %%n in (1,1,10) DO echo %%n
FOR /L %%n in (1 1 10) DO echo %%n
FOR /L %%n in (1;1;10) DO echo %%n
FOR /L %%n in (1=1=10) DO echo %%n
FOR /L %%n in (1;,,;==,,; 1;=,,;;==;,;;10) DO echo %%n
FOR /L %%n in (1+Pi/2=1-sin(360°^)=10E-20*array[4]) DO echo %%n
jeb