replace string that contains ">>" within the string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mintoo2cool
Posts: 1
Joined: 25 Oct 2011 04:09

replace string that contains ">>" within the string

#1 Post by mintoo2cool » 07 Dec 2011 02:47

Hi,

I have a rather peculiar issue here.

Basically my objective is to replace a particular string with another string in a file.

Allow me elaborate.

I have within a file the statement

Code: Select all

sqlplus -s username/password @sqlfile.sql >>outputfile.sql


I have this vbscript that accepts the username/password string from user and stores it in an enviornment variable.

Next I have to replace the existing username/password with the username/password given by user.

For replacing I have another vbscript that takes the existing string , replacement string and filename as parameters and replaces the existing string with the replacement string.


The exact steps that I m following is

Code: Select all

rem userin.vbs takes the user input
start /w wscript.exe vb/userin.vbs
rem userin.bat set the user input as enviornment variable
call vb/userin.bat
del vb\userin.bat
rem finds the current sqlplus statement in the file and stores the entire string in myvar variable. (it will the statement as follows: sqlplus -S <current username/password> @temp1.sql >>opfile.sql)

for /f "tokens=*" %%a in (
'findstr sqlplus process\subshellexec.bat'
) do (
set myvar=%%a
)

rem set the user entered username/password string and store the entire sqlplus statement in newvar variable.

set newvar ='sqlplus -S %USERIN% @temp1.sql >>opfile.sql'

rem call replacedir.vbs which replaces the existing sqlplus sentence with the new sqlplus sentence.
call cscript vb/replacedir.vbs process\subshellexec.bat "%myvar%" "%newvar%"



Now the problem here is that the variable

Code: Select all

set newvar =set newvar ='sqlplus -S %USERIN% @temp1.sql >>opfile.sql'

is not getting initialized properly.

Infact, the string "sqlplus -S <new username/password> @temp1.sql" gets appended to opfile.sql file, because of ">>". And the variable newvar stores nothing.

How do I properly initialize the newvar variable without the information getting redirected?

Thanks.

jeb
Expert
Posts: 1059
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: replace string that contains ">>" within the string

#2 Post by jeb » 07 Dec 2011 04:19

Hi mintoo2cool,

Code: Select all

set "newvar='sqlplus -S %USERIN% @temp1.sql >>opfile.sql'"


With the extended Set-Syntax, you can quote a set command, without inserting the quotes.

You should avoid spaces between variable and the equal sign, else you create a variable with the name "newVar<space>".

Btw. I didn't understand exactly what are you trying, but I assume your way is a bit too complex.
Why you want to call you vbs with the complete newvar?

jeb

Post Reply