Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

modify batch script

As a follow-up to this question (https://www.experts-exchange.com/questions/28667295/modify-batch-script-which-outputs-dsquery-user-results.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!
Avatar of Gabriel Clifton
Gabriel Clifton
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samiam41

ASKER

Hey Gabriel.  Thanks for the suggestion.

When I change the token value to 2,3,7 - the output is only tokens 2 and 3.
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.
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.
Avatar of oBdA
oBdA

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.