samiam41
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):
Thank you!
(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]
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
When I change the token value to 2,3,7 - the output is only tokens 2 and 3.
ASKER
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.
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.
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.
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.
"tokens=3,7
so if you want 2,3,7 you change to "tokens=2,3,7