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?
 
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
 
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
 
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.