46,327 questions
Unable to edit .xml file to replace last occurence of search item?
Asad A
20
Reputation points
``I want to replace following string in the xml file which is the last last entry, there are multiple entries
for
keystoreFile
and
keystorePass
my script here
for testing I try to change first string which is keystoreFile
@echo off
set DESTINATION_DIRECTORY=%CD%
set KEYSTORE_NAME=minus
echo.
set /p PASS=Enter your store password in order to update the server.xml config file#
setlocal enabledelayedexpansion
set "search_string=./conf/server.keystore
set "replacement_string=%DESTINATION_DIRECTORY%\%KEYSTORE_NAME%.keystore" keystorePass="%PAS%""
for /f "tokens=*" %%a in ("server.xml") do (
set "line=%%a"
setlocal enabledelayedexpansion
echo !line:%search_string%=%replacement_string%!
endlocal
) >> help10008.xml
The output I get is messy,
original
<Connector SSLEnabled="true" URIEncoding="UTF-8" acceptCount="100" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA" clientAuth="false" connectionTimeout="20000" debug="0" disableUploadTimeout="true" enableLookups="false" keystoreFile="./conf/server.keystore" keystorePass="adventnet" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" name="agentSSL" port="8555" scheme="https" secure="true" sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2" sslProtocol="TLS"/>
expected
<Connector SSLEnabled="true" URIEncoding="UTF-8" acceptCount="100" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA" clientAuth="false" connectionTimeout="20000" debug="0" disableUploadTimeout="true" enableLookups="false" keystoreFile="C:\Program Files\ManageEngine\ADAudit Plus\conf\minus.keystore" keystorePass="adventnet" maxSpareThreads="75" maxThreads="150" minSpareThreads="25" name="agentSSL" port="8555" scheme="https" secure="true" sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2" sslProtocol="TLS"/>
but it also add erroneous data e.g
./conf/server.keystore=C:\Program Files\ManageEngine\ADAudit Plus\conf\minus.keystore
in place of
`keystoreFile="./conf/server.keystore"` from the original xml, which I don't want I want somehow to match only the last entry the which is xml tag as shown above.
you may view the two xml files named good and bad accordingly, I try to upload it here but I was getting errors, sorry for the trouble.
Community Center | Not monitored
Sign in to answer