alexmngn
alexmngn

Reputation: 9597

Search and replace with quote in batch script

I'm trying to search and replace a string containing a double quote with another string but I got some issue.

I'm reading a file line per line, and searching in this line if there's a match for a replace

Example:

%%l contain a line read from a file. For this example, %%l = myVar: "../folder"+var

set s=%%l
set sch="+var
set rpl=val
set s=%s:!sch!=!rpl!%
echo !s!

Here, I want to replace "+var with val

But doing this, it's not working. My echo !s! return "+var=val only

I also tried:

set s=%%l
set rpl=val
set s=%s:"+var=!rpl!%

And it doesn't work.

Any idea?

Thanks

Upvotes: 1

Views: 187

Answers (1)

gonzalezea
gonzalezea

Reputation: 472

Try changing replace line for this:

set s=!s:%sch%=%rpl%!

Upvotes: 1

Related Questions