In a standard windows batch file (.cmd) I want to do:
FOR /F "skip=0" %%G IN (filename.txt) DO ( ECHO %%G )
but I get " was unexpected at this time.
"skip=1"
works fine (In my actual code 0
is a variable).
According to ss64.com the default is skip=0
, but it seems not to work when explicitly set.
Am I doing it wrong? Or is there a workaround I can use?
Edit:
I have tried this on both Windows server 2003 and Windows 7.
The content of filename.txt could be:
something
stuff
unicorns
It really doesn't like the 0
, causing the parser to expect more after it (You can also trip it when trying to use 09
which it tries parsing as octal, which fails).
I guess you need to create an environment variable holding the entire skip=n
part or nothing and insert that into the argument list. Something like
if %N% GTR 0 (
set SKIP="skip=%N%"
) else (
set SKIP=
)
and then use
for /f %SKIP% %%G ...
(or without the quotes if you need to pass more options).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With