modify batch script

As a follow-up to this question (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28667295.html), I need to show tokens 2, 3 and 7 instead of just 3 and 7.  How do I accomplish this?  

(ref script):
@echo off
cls
set findstring=
set /p "findstring=Enter in user's first name or string: "
for /f "tokens=3,7 delims=,=" %%a in ('dsquery USER "ou=x,ou=x,dc=x,dc=x,dc=x,dc=x" -name *"%findstring%"*') do echo %%a [%%b]

Open in new window


Thank you!
LVL 9
samiam41Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gabriel CliftonNet AdminCommented:
You can add whichever you want right here
"tokens=3,7
so if you want 2,3,7 you change to "tokens=2,3,7
0
oBdACommented:
The same way as with two: you just set the "tokens=...", then use the respective loop variables beginning with the one you defined (in this case %%a):
@echo off
cls
set findstring=
set /p "findstring=Enter in user's first name or string: "
for /f "tokens=2,3,7 delims=,=" %%a in ('dsquery USER "ou=x,ou=x,dc=x,dc=x,dc=x,dc=x" -name *"%findstring%"*') do echo Token 2: %%a, token 3: [%%b], token 7: [%%c]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
samiam41Author Commented:
Hey Gabriel.  Thanks for the suggestion.

When I change the token value to 2,3,7 - the output is only tokens 2 and 3.
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

samiam41Author Commented:
Now I get it!!  Thanks for the help.  I removed the word "token" after the echo portion of the code and the results look exactly like I wanted them to.
0
Gabriel CliftonNet AdminCommented:
Sorry, you also have to add the extra variable to output, do echo %%a [%%b] %%c

Also, if you want a range in the tokens such as 2 through 7, you can do "tokens 2-7

Just remember if you want to display your variable you need to do something with it like echo.
0
oBdACommented:
When you're using three tokens, you need to use the respective variables as well; in this case %%a, %%b, %%c; %%b and %%c are implicitly defined based on the "beginning" variable %%a and the number of tokens defined.
Examples:
In for /f "tokens=1-4" %%a ... the available loop variables would be %%a, %%b, %%c, %%d.
In for /f "tokens=1,5,9" %%m ... the available loop variables would be %%m, %%n, %%o.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.