Solved Token doesn't reads after space.

June 1, 2012 at 11:19:08
Specs: Windows 7, Core 2 Duo 2.93 GHZ/ 2048 MB
Thanks for this tutorial, it helped me a lot.

I couldn't solve one problem.

I want to read a value for registry and assign it in a variable.
First I typed this:
Reg.exe QUERY "HKLM\Software\Try" /v "test" |Findstr.exe /ri "\<test\>"

Output: test REG_SZ C:\Program Files\Common Files

I want to copy "C:\Program Files\Common Files" in a variable.
So i tried this


For /f "tokens=3 delims= " %%a in ('Reg.exe QUERY "HKLM\SOFTWARE\try" /v "test" ^|Findstr.exe /ri "\<test\>"') do echo %%a

output:C:\Program
I tried token=3* also but it didn't worked.
I didn't tried "token=3-5" since value may differ in other system.
So, I need to copy all values after token 3.

Please help....


See More: Token doesnt reads after space.

Report •


#1
June 1, 2012 at 15:38:24
Try:

For /f "tokens=1-2* delims= " %%a in ('Reg.exe QUERY "HKLM\SOFTWARE\try" /v "test" ^|Findstr.exe /ri "\<test\>"') do echo %%c


Please come back & tell us if your problem is resolved.


Report •

#2
June 1, 2012 at 23:41:34
Thanks for replying.

Doesn't work.
Output: test


Report •

#3
June 2, 2012 at 00:56:50
✔ Best Answer
Please confirm that you changed the %%a variable to %%c at the end of the command line as shown in my first response and emboldened below:

For /f "tokens=............... /v "test" ^|Findstr.exe /ri "\<test\>"') do echo %%c


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
June 2, 2012 at 12:13:00
Awesome it worked,

I am beginner in bat files, can you give me a small explanation?
I didn't understood "token=1-2* and "%%c".

Thanks for solving it!!!


Report •

#5
June 2, 2012 at 14:53:52
You obviously know what tokens are so for this explanation we'll stay with the example you posted.

test REG_SZ C:\Program Files\Common Files

Using space as the delimiter and beginning with %%a as the first For variable Tokens=1-2* will allocate variable %%a to the first token (test), %%b to the second (REG_SZ) and * will cause the remainder of the input (C:\Program Files\Common Files) to be allocated to the next variable (%%c) disregarding any delimiters.

Hope this helps.


Please come back & tell us if your problem is resolved.


Report •

#6
June 2, 2012 at 21:16:48
got it.

Thanks once again.


Report •

Ask Question