for /f loop "tokens and delimiters" didn't work with variables (batch file) -
recently making batch file ran problem, when made /f loop, used variable in "tokens", example:
for /f "delims= tokens=!count2!" %%a in ('type test.txt 2^>nul') (
like can see, have variable !count2!
, in loop. , when tested it, displayed !count2!" unexpected @ time
. , dont know why?
can help?
here full code of have tried:
@echo off setlocal enableextensions enabledelayedexpansion set "count1=0" set "count2=0" /l %%b in (1 1 10) ( set /a "count2+=1" set /a "count1+=1" /f "delims= tokens=!count2!" %%a in ('type test.txt 2^>nul') ( set "str!count1!=%%a" ) ) echo !str1! !str2! !str3! !str4! pause
by way, test.txt contains test hello # ###
and, want set test
, hello
, #
, ###
own variable (str1, str2, str3 , str4).
and yes have tried % instead of !
tell me if wasn't clear enough!
thanks :)
why bothering tokens?
@echo off setlocal enabledelayedexpansion set /a count=0 /f "delims=" %%i in (test.txt) %%j in (%%i) ( set /a count+=1 set str!count!=%%j ) set str
Comments
Post a Comment