|
Question : How to seperate parts of a line using FOR and FINDSTR
|
|
I would like to be able to parse a line of text, and replace a particular value with another, before importing back into the registry, but the FOR command doesn't seem to be behaving itself!
Here's what I have so far:
------------------ regedit /e export.reg "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers"
for /f "usebackq delims=" %%i in (`type export.reg ^| findstr "\"Port\"= \\Printers\\"`) do call :x1 %%i goto exit
:x1 for /f "usebackq delims= tokens=*" %%j in (`echo %*`) do echo %%j goto :eof ------------------
1. I use 'type' as this converts from Unicode to DOS (which is required by FIND etc.) 2. The first use of findstr successfully returns all the registry keys, and lines which contain "Port"= 3. When I call :x1, "echo %*" works, but when I try to use the for command to show the line (before attempting to seperate it into tokens), it only shows perhaps 12 out of 61 lines, and of those it shows, it strips the = sign out of them!
If it helps, what I am trying to do (using only regedit, and not reg.exe) is search the registry key for values of printer ports (eg. "Port"="IP_10.1.1.25") and replace it with the hostname instead (eg. "Port"="printer25").
When I can extract the IP address using the above method, I will use nslookup to retrieve the correct hostname before importing it back into the registry.
Many thanks, Steve :)
|
|
Answer : How to seperate parts of a line using FOR and FINDSTR
|
|
Try this out:
for /f "usebackq tokens=*" %%j in (`echo "%*"`) do echo %%~j
Good Luck, Steve
|
|
|
|