Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
einstein1969
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
#1
Post
by einstein1969 » 01 Nov 2022 09:00
Hello,
I need help with a for /f
if I run this code, the for /f gives me an error
Code: Select all
@echo off & setlocal enableDelayedExpansion
>"%TMP%\env.txt" set
set /a nl=10
(
for /f "skip=!nl! eol== delims==" %%V in (%TMP%\env.txt) do set "%%~V="
)
the for is inside a block, can someone explain to me how to solve it and why it don't works?
-
miskox
- Posts: 630
- Joined: 28 Jun 2010 03:46
#2
Post
by miskox » 01 Nov 2022 10:10
If I replace
with
it works.
Why? Maybe % should not be replaced by ! (%%a is not replaced by !!a for example) in the command itself.
Saso
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#3
Post
by aGerman » 01 Nov 2022 13:57
If you really need the delayed expansion of n1 then your best bet might be to run the loop in a subroutine. Another approach could be processing the output of MORE +!n1! "filename".
Steffen
-
einstein1969
- Expert
- Posts: 960
- Joined: 15 Jun 2012 13:16
- Location: Italy, Rome
#4
Post
by einstein1969 » 02 Nov 2022 05:46
thanks
i use "more +!nl!" is more efficient