Google Answers Logo
View Question
 
Q: Searching and replacing text from a batch file ( No Answer,   3 Comments )
Question  
Subject: Searching and replacing text from a batch file
Category: Computers > Programming
Asked by: thray-ga
List Price: $15.00
Posted: 03 Jan 2006 15:32 PST
Expires: 04 Jan 2006 13:12 PST
Question ID: 428674
I need to modify a .reg file, and replace all occurences with
'InsertPathHere' (That is the literal string) with the current working
directory. I need to do this from within a batch file without user
interaction, and I need to use only freeware. This is so that I can
add path entries to the registry from a drive with a variable drive
letter (a USB drive). The result needs only work on Windows 2000 and
XP, but it might come in handy to be able to use it on ME/98 in the
future.

I have faced quite a bit of difficulty finding a freeware utility to
do this for me because, although I may find something that does search
and replace, it does it on full lines only or can not substitute text
within a string.

Input text example: InsertPathHereBlah.dll
Output example: E:\\Moo\\Blah.dll
Answer  
There is no answer at this time.

Comments  
Subject: Re: Searching and replacing text from a batch file
From: lukebakken-ga on 03 Jan 2006 19:38 PST
 
Download "sed" from here:

http://prdownloads.sourceforge.net/gnuwin32/sed-4.1.4.exe?download

Install to whatever directory you want, I installed to C:\GnuWin32

sed.exe will be in C:\GnuWin32\bin

In your batch file insert the following commands:

set PATH=C:\GnuWin32\bin;%PATH%
sed -e "s/InsertPathHere/E:\\Moo\\Blah\\/g" inputfile.txt > %TEMP%\tmpfile.out
copy tmpfile.out inputfile.txt

If you want to copy sed.exe to removable storage, be sure to also get
the following files:

C:\GnuWin32\bin\libintl3.dll
C:\GnuWin32\bin\libiconv2.dll
Subject: Re: Searching and replacing text from a batch file
From: mister4u-ga on 04 Jan 2006 10:25 PST
 
http://www.resplendence.com/registrar_features_search
Resplendent Registrar offers a fast and convenient way to search the
registry or  a specified key for text occurrences. Matching items can
optionally be replaced with other text, deleted, or  exported to a
registry file.

Text and binary searches as well as regular expressions are supported.
http://www.funduc.com/registry_toolkit.htm 


http://downloads.theregister.co.uk/Windows/Utilities/Registry/registry-search.html
Subject: Re: Searching and replacing text from a batch file
From: thray-ga on 04 Jan 2006 12:49 PST
 
Sed produces junk results in the .reg file for some reason, and does
not replace the text using the method you described. I already tried
it, and I tried the one you linked to as well since I got it from a
different source.

In a text file, the text is replaced sucessfully, in the .reg file..
well, here's an excerpt:

Original:

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{01D01C06-959A-4A94-9B3B-451A4896009C}\InprocServer32]
@="InsertPathHere\\Audit.dll"
"ThreadingModel"="Apartment"

Output after sed -e "s/InsertPathHere/Test/g" original.reg > temp.reg

????????????????????????????????????????????????
???????????????????????????????????????????????????
@="InsertPathHere\\Audit.dll"
???????????????????????????????

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy