I have one text file (index.txt) need replace strings. And also I have a variable file as pkg_data_temp.txt
Now I used this below scripts to replace, and most string works fine except two strings only replaced the first part, the remaining is still old
Code: Select all
for /f "tokens=1-2 delims=" %%A in (C:\temp\pkg_data_temp.txt) do call :schemes %%A %%B
EXIT /B %ERRORLEVEL%
:schemes
set osch=%~1
set nsch=%~2
echo %osch%
echo %nsch%
cd C:\temp
::index.txt
Set "search=%osch%"
Set "replace=%nsch%"
Set "textfile=index.txt"
Set "newfile=indesnew.txt"
(
For /F "Tokens=1* Delims=:" %%A In ('FindStr /N "^" "%textfile%"') Do (
If "%%B"=="" (
Echo=
) Else (
Set "line=%%B"
SetLocal EnableDelayedExpansion
Set "line=!line:%search%=%replace%!"
Echo=!line!
EndLocal
)
)
)>"%newfile%"
Del "%textfile%"
Ren "%newfile%" "%textfile%"
::Readme-how-to-use-this-package.txt
Set "search=%osch%"
Set "replace=%nsch%"
Set "textfile=Readme-how-to-use-this-package.txt"
Set "newfile=indesnew.txt"
(
For /F "Tokens=1* Delims=:" %%A In ('FindStr /N "^" "%textfile%"') Do (
If "%%B"=="" (
Echo=
) Else (
Set "line=%%B"
SetLocal EnableDelayedExpansion
Set "line=!line:%search%=%replace%!"
Echo=!line!
EndLocal
)
)
)>"%newfile%"
Del "%textfile%"
Ren "%newfile%" "%textfile%"
ping -n 1 127.0.0.1 >NUL
EXIT /B %ERRORLEVEL%
+++++++++++
"T501-08680-0103,0501-08690-0100,T503-08961-0100,T501-08699-0100" "T501-08665-0103,T504-08896-0100,0501-08658-0100,T504-08961-0100"
"T503-08667-0108" "T504-08667-0108"
"T503-08667-0109,T503-08939-0100" "T504-08667-0109,T504-08939-0100"
"T503-08667-0108,T501-08699-0100,T503-08966-0100" "T504-08667-0108,T504-08896-0100,T504-08966-0100"
"T503-08667-0108,T503-09055-0101,T501-08699-0100,T503-08961-0100" "T504-08667-0108,T504-08896-0100,T504-08961-0100,T504-09055-0101"
"T503-08667-0105,T501-08699-0100" "T504-08667-0105,T504-08896-0100"
"T503-08667-0109,T501-08699-0100,T503-08961-0100" "T504-08667-0109,T504-08896-0100,T504-08961-0100"
+++++++++++
This is old text looks like
- 852046 Version: 0912 (T503-08667-0109,T503-08939-0100)
852047 Version: 0912
852059 Version: 0912 (T503-08667-0108,T501-08699-0100,T503-08966-0100)
852060 Version: 0912 (T503-08667-0108,T503-09055-0101,T501-08699-0100,T503-08961-0100)
852063 Version: 0912
852069 Version: 1012 (T503-08667-0105,T501-08699-0100)
NAR_Apps_Signed_Resources
829549 Version: 1012
829625 Version: N/A
844330 Version: N/A
847901 Version: N/A
T3Admin Version: N/A
852046 Version: 0912
SRED_Comp Version: 0912
NAR_Apps_Signed_Resources_CA
852059 Version: 0912
NAR KIA
929500 Version: 0627 (T501-08680-0103,0501-08690-0100,T503-08961-0100,T501-08699-0100)
NAR TSA
829501 Version: 0662 (T503-08667-0109,T501-08699-0100,T503-08961-0100)
NarEmvService
- 852046 Version: 0912 (T504-08667-0109,T504-08939-0100)
852047 Version: 0912
852059 Version: 0912 (T504-08667-0108,T501-08699-0100,T503-08966-0100)
852060 Version: 0912 (T504-08667-0108,T503-09055-0101,T501-08699-0100,T503-08961-0100)
852063 Version: 0912
852069 Version: 1012 (T504-08667-0105,T504-08896-0100)
NAR_Apps_Signed_Resources
829549 Version: 1012
829625 Version: N/A
844330 Version: N/A
847901 Version: N/A
T3Admin Version: N/A
852046 Version: 0912
SRED_Comp Version: 0912
NAR_Apps_Signed_Resources_CA
852059 Version: 0912
NAR KIA
929500 Version: 0627 (T501-08665-0103,T504-08896-0100,0501-08658-0100,T504-08961-0100)
NAR TSA
829501 Version: 0662 (T504-08667-0109,T504-08896-0100,T504-08961-0100)
NarEmvService