Reputation: 1365
I know this question is asked many times, but I didn't get the answer for what I am searching.
I want to replace a pattern using windows .bat
file.
I know how to replace X
with Y
.
But I am trying to replace say installPath
with C:\Programfiles\Install\
.
Here, I am facing issues as the new value string contains \
i.e special character.
Please let me know how I can replace this.
Upvotes: 0
Views: 5954
Reputation: 873
This should work... By the way, this is my first post on this website. The following uses delayed expansion so that you have two different 'variable symbols' to play with:
setlocal enabledelayedexpansion
set iPath=installPath
set input=C:\Programfiles\Install\
set p=!iPath:installPath=%input%!
Hope this helps
Upvotes: 0
Reputation: 484
Followinf script will find the string in the file and replace with another string. EX. "installPath" will be replaced with "C:\Programfiles\Install"
@echo off
for /f "usebackq tokens=*" %%a in ("test.txt") do call :Replace "%%a"
del "test.txt"
rename "newfile.txt" test.txt
exit /b
:Replace
set str1=%~1
set str1=%str1:installPath=C:\Programfiles\Install%
echo.%str1%>>"newfile.txt"
exit /b
Upvotes: 1
Reputation: 31231
This works fine for me
set p=installPath
set p=%p:installPath=C:\Programfiles\Install\%
echo %p%
Upvotes: 1
Reputation: 145
Perhaps this tool might help you:
http://sourceforge.net/projects/fart-it/
Upvotes: 0