Computing.Net > Forums > Windows XP > Shifting variables in for /f

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shifting variables in for /f

Reply to Message Icon

Name: iborg
Date: July 19, 2009 at 23:15:29 Pacific
OS: Windows XP
Subcategory: Software Problems
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: July 19, 2009 at 23:53:19 Pacific
Reply:

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


0

Response Number 2
Name: iborg
Date: July 19, 2009 at 23:59:04 Pacific
Reply:

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 :-((


0

Response Number 3
Name: Judago
Date: July 20, 2009 at 00:19:49 Pacific
Reply:

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.


0

Response Number 4
Name: iborg
Date: July 20, 2009 at 00:29:16 Pacific
Reply:

Awesome!!!
That did the job smoothly!
Thanx a lot Judago!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Shifting variables in for /f

Batch script problem with FOR /F www.computing.net/answers/windows-xp/batch-script-problem-with-for-f/143792.html

CMD: Using variables in templates www.computing.net/answers/windows-xp/cmd-using-variables-in-templates/161092.html

Multiple do commands in for loop www.computing.net/answers/windows-xp/multiple-do-commands-in-for-loop/168961.html