Shifting variables in for /f

July 19, 2009 at 23:15:29
Specs: Windows XP
Hi,
I need help with this one.
I want to shift variables in a for /f loop. For example
for /f "tokens=1,2,3,4,5,6,7,8,9 delims=:" %%a in ('@echo %trk%') do echo %%a %%b %%c %%d %%e %%f %%g %%h %%i
(%trk% may contains something like 1:2:4:6:7:8:12)
So instead of writing code to handle all the %%a to %%i variables I prefer to use a shift like method to process %%a only. This also helps to avoid extra code to handle how many variables have data inside.

Thanx a lot


See More: Shifting variables in for /f

Report •


#1
July 19, 2009 at 23:53:19
here's a vbscript. Although its entirely up to you, i would recommend you learn about it, if you want to do scripting/batching on Windows.
strData = "1:2:4:6:7:8:12"
ArrData = Split(strData,":") 'split on ":"
For i=LBound(ArrData) To UBound(ArrData)
	'Print out the elements.
	WScript.Echo ArrData(i)
Next

GNU win32 packages | Gawk


Report •

#2
July 19, 2009 at 23:59:04
Thanx for the vbscript.
The thing is that although i know vbscript (and as you demonstrated its a nobrainer to do the job) this specific script must be written in dos batch :-((

Report •

#3
July 20, 2009 at 00:19:49
What about:

for %%a in (%trk::= %) do (
    REM your stuff with %%a
)

If you variable contains <, >, |, ^, ;, =, a comma or tab it won't work as expected, since you only have numbers it shouldn't be a problem.


Report •

Related Solutions

#4
July 20, 2009 at 00:29:16
Awesome!!!
That did the job smoothly!
Thanx a lot Judago!

Report •


Ask Question