Removing or Preventing leading spaces
Posted: 28 Sep 2009 14:06
Hello
I am extracting certain values out of the registry using REG QUERY by piping them through FIND and then writing the data to a text file. An example of the code...
Below is an example of the text file that was created...
My question is this:
How can I either strip, or prevent the 4 leading spaces in this text file. My goal is to parse through the file and strip out the 1st token and then surround them in quotes like this:
...but I'm having difficulty because of the leading TAB/4 spaces that is created during the text file creation. Using this command line generates this output:
...And this code generates this:
Thanks in advance for your help.
I am extracting certain values out of the registry using REG QUERY by piping them through FIND and then writing the data to a text file. An example of the code...
Code: Select all
REG QUERY HKCU\Software\Microsoft\Windows\CurrentVersion\Run /S | FIND /I "123.exe" > %TEMP%\query.txt
Below is an example of the text file that was created...
Code: Select all
A3 1 REG_SZ C:\DOCUME~1\user\APPLIC~1\123.exe
A REG_SZ C:\Documents and Settings\user\Local Settings\Temp\123.exe
A1 REG_SZ C:\DOCUME~1\user\LOCALS~1\Temp\123.exe
A2 REG_SZ C:\Documents and Settings\user\Application Data\123.exe
My question is this:
How can I either strip, or prevent the 4 leading spaces in this text file. My goal is to parse through the file and strip out the 1st token and then surround them in quotes like this:
Code: Select all
"A3 1"
"A"
"A1"
"A2"
...but I'm having difficulty because of the leading TAB/4 spaces that is created during the text file creation. Using this command line generates this output:
Code: Select all
FOR /F "TOKENS=1 DELIMS= " %A IN (%TEMP%\query.txt) DO @ECHO "%A"
" A3 1"
" A"
" A1"
" A2"
...And this code generates this:
Code: Select all
FOR /F "TOKENS=1,2* " %A IN (%TEMP%\query.txt) DO @ECHO "%A %B"
"A3 1"
"A REG_SZ"
"A1 REG_SZ"
"A2 REG_SZ"
Thanks in advance for your help.