Re: Remove Carriage return in BATCH file



wayne schrieb:
HELP this is driving me crazy.
I've been learning a lot of great things about batch commands recently, and often use a | find trick to read things I need from various files or registry queries. Specifically I use reg.exe a lot to get info out of the registry and do something with it.
HOWEVER. the reg.exe I've been using is an old version that outputs each "key" as a single line of text, so that if I use a
| find "SQL" on a key I would get, I can also get the path of what I found.
for example

HKEY_CLASSES_ROOTInstaller\Products\\\7DDFFFA258DE09A4C825D59ABECDB9F8\ProductName : Microsoft SQL Server 2005 Express Edition CTP (SQLEXPRESS)

But the new reg.exe (That ships with Windows) puts it's output on multiple lines like so...

HKEY_CLASSES_ROOT\Installer\Products\\7DDFFFA258DE09A4C825D59ABECDB9F8
ProductName REG_SZ Microsoft SQL Server 2005 Express Edition CTP (SQLEXPRESS)
PackageCode REG_SZ FE472E251BF04D52CDDBFE8D28E45A77
Language REG_DWORD 0x409
Version REG_DWORD 0x900045c
Transforms REG_EXPAND_SZ :SqlRun01.mst;:InstID01.mst;:InstName01.mst
Assignment REG_DWORD 0x1
AdvertiseFlags REG_DWORD 0x184
ProductIcon REG_SZ c:\WINDOWS\Installer\{2AFFFDD7-ED85-4A90-8C52-5DA9EBDC9B8F}\ARPIcon.ico
InstanceType REG_DWORD 0x1
AuthorizedLUAApp REG_DWORD 0x0
Clients REG_MULTI_SZ :\0\0

Which is pretty, and useful if I want to pipe it to a text file (which I don't need to do because I could export it instead) but is useless for using find if I want to get back something else from the key. For example, the above find would return:

ProductName REG_SZ Microsoft SQL Server 2005 Express Edition CTP (SQLEXPRESS)

Which tells me nothing about the key itself. In other words, now all I can do is see if Microsoft SQL Server 2005 Express Edition is installed, I can't find it's icon, or it's GUID, or it's package code etc...

What I need to know is if there is a way to force it back to the old style, or if I can have a FOR /f loop break it up on blank lines instead of line feeds or anything that would let me get ALL of the information about a key if I find the info in it's query that I'm keying in on.


Hello Wayne,
I miss some information:
- which windows version
- which reg.exe,
- what is your actual code

Is your sample output from a reg query with /s (subkeys) ?

If you are after special values use /v (assuming reg.exe ver 3.0)

for parsing there are several possible ways.

Here is one to play with:


@echo off
setlocal EnableExtensions
set key=hkcr\installer\products
for /f "tokens=4 delims=\" %%A in (
'reg query "%key%" ^|findstr "products."'
) do (setlocal
for /f "skip=4 tokens=1-2,*" %%B in (
'reg query "%key%\%%A"'
) do set my_%%B=%%D
set my_
endlocal
pause
)


HTH

--
Greetings
Matthias
.


Loading