Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Double quotes in cmd

$
0
0

Hi All,

Hopefully this is a very straightforward question, and apologies for asking if so but despite a lot of googling I can't quite get to the bottom of it :(

With the below code I'm simply trying to replace a string in a txt file, but as the 'Set' command already uses the = symbol, which happens also to be contained in the string I wish to replace, it doesnt execute correctly.

I'm guessing i need to wrap the second = in quote also somehow, but can't quite figure it out. 

@echo off
set "replace=#user=guest"
set "replaced=user=StoreUser1"

set "source=C:\Users\adam\Desktop\test.txt"
set "target=C:\Users\adam\Desktop\test1.txt"

setlocal enableDelayedExpansion
(
   for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %source%') do (
      set "line=%%b"
      if defined line set "line=!line:%replace%=%replaced%!"
      echo(!line!
   )
) > %target%
endlocal

Any help would be greatly appreciated!

Adam


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>