Reputation: 1
I'm running a .BAT script that is reading a text file and searching for a key word that starts with "HKLM" at the front of the text line in the said text file. The input file is a saved audit request file so there is normal verbiage and then the HKLM registry keys. My task is to pull the registry keys and then run the REG QUERY on the keys.
I've been looking at examples and found this for loop to be pretty handy:
for /f %%i in ('FINDSTR /B /I "HKLM" %tmp_result_file%') do (
IF "%%i" == "" (ECHO xx) ELSE ECHO %%i
)
The problem I'm having is that if there is a space in the line that I am matching against the search key HKLM, %%i only displays the line up to the space. Here's a line in the input file:
HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE
You will note the space between "Internet Explorer". When I run my .bat file I get the following output:
C:\Work>1test.bat
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
HKLM\Software\Microsoft\Internet
C:\Work>
This shows how I am only getting 1/2 the line where everything prints up to the space. Can anyone give some hints on how to print the whole line as listed in the input file?
One additional question: Is there a way to have more than 1 queries in the findstr
Upvotes: 0
Views: 144
Reputation: 4750
One way: This specifies that there are no characters to delimit tokens.
for /f "delims=" %%i ...
Another way: This treats the entire string as one token
for /f "tokens=*" %%i ...
One of the ways will remove leading spaces, but that is not a concern here.
As far as your 2nd question... Yes, just pipe the output of the FINDSTR command to another FINDSTR command. In your case (in a FOR construct) you will need to escape the pipe symbol like this ^|
Upvotes: 1