PDA

View Full Version : Replacing Text in Batch File



neddyflanders
11-18-2005, 03:34 PM
Hello, I am trying to find the best way to replace text in a batch file. I have used FileGrep, FileDeleteLine & FileInsertLine before but this time I only want to replace part of the line. For Example the batch file contains many lines (about 40)like below

Server[SERVER] Database[Database] script.vbs
Server[SERVER] Database[Database] script2.vbs

I just want to go in and replace Server and Database with properties that I am getting from the user(Each line will only need those two values replaced). Each vbs script is different so I don't want to delete the line, just replace those two values. Also the brackets are just for an example, their not in regular file just using them as example.

What I want is:
Server TestServer1 Database TestDatabase1 script.vbs
Server TestServer1 Database TestDatabase1 script2.vbs
Server TestServer1 Database TestDatabase1 script3.vbs


Any help would be appreciated.

RobertDickau
11-20-2005, 10:14 AM
If you're using InstallScript, this example claims to do what you want: www.installsite.org > InstallScript Samples > Strings > Replace a String in a File...

Christopher Painter
11-20-2005, 11:00 AM
This type of change can also be made simple by using environment variables and the ECHO and TYPE command.

For example:

Include a file in the install called commands.txt

Server %MyAppServer% Database %MyAppDataBase% script1.vbs
Server %MyAppServer% Database %MyAppDataBase% script2.vbs
Server %MyAppServer% Database %MyAppDataBase% script3.vbs

Have a DOS or Script custom actions that does something like

cmd /c echo set MyAppServer=[ServerName] > script.bat
cmd /c echo set MyAppDatabase=[Database] >> script.bat
cmd /c type commands.txt >> script.bat

srikapat
11-20-2005, 09:45 PM
u can also make use of "replace" function if you are using VBScript custom action.