Reputation: 4364
I'm trying to write a batch script that changes a line in one of my files.
text.file:
ex1
ex2
<"ex3">
ex4
I want to replace <"ex3">
with <"ex5">
. I am currently using this code:
@echo off
SETLOCAL=ENABLEDELAYEDEXPANSION
rename text.file text.tmp
for /f %%a in (text.tmp) do (
set foo=%%a
if !foo!=="<"ex3">" set foo="<"ex5">"
echo !foo! >> text.file)
del text.tmp
How do I escape "
so that I can compare the string with the value in foo
? I have tried using \"
, ^"
, and ""
. With the first two, I get The syntax of the command is incorrect
, and with the last one nothing happens.
Upvotes: 0
Views: 61
Reputation: 311
This should work
@echo off
SETLOCAL=ENABLEDELAYEDEXPANSION
rename text.file text.tmp
for /f %%a in (text.tmp) do (
set foo=%%a
if "!foo!"=="<"ex3">" set "foo=<"ex5">"
echo !foo! >> text.file)
del text.tmp
Upvotes: 2