I am trying my first attempt at a simple batch script and am most of the way there but am struggling with getting the terminal window to correctly keep the user up to date with what's going on.
The script below works in terms of replacing text in a file, however I would like it to echo out a message once if the string is found and replaced. At the moment it appears to always run the else command so any echo placed there is outputted for each line.
Code: Select all
@echo off
:: This script toggles text
title Text Toggler
:: Set variables
set iniFile=C:\Program Files (x86)\Client.ini
set onPrem=192.168.40.108,192.168.40.109
set ultra=ultra.companyname1.net
:: N.b. I have anonymised the company name but the string length is the same
for /f "delims=" %%i in ('type "%iniFile%" ^& break ^> "%iniFile%" ') do (
set line=%%i
setlocal enabledelayedexpansion
if !line:~-22!==%ultra% (
>>"%iniFile%" echo(!line:%ultra%=%onPrem%!
:: I would like to echo here if the line is found. Even better would be a counter that gets incremented, then if said counter is >0 at end of script can then echo once
:: there
) else (
if !line:~-29!==%onPrem% (
>>"%iniFile%" echo(!line:%onPrem%=%ultra%!
:: Similar to above, I would like to echo here if the line is found. Again, as multiple replacements may happen a better solution would use a counter and then
:: at the end of the script
)
)
endlocal
)
Pause
So to summarise, I simply want to toggle between having the IP addresses and the DNS address, then echo which one is now in the file (e.g. echo DNS active)[System]
Encryption.Scheme=on
MultiInstance.Enabled=false
Provisioning.Broker=true
Provisioning.IP=192.168.40.108,192.168.40.109
Encryption.ForcePeerVerification=false
Encryption.DisableSignatureVerification=true
[Transfer]
Transfer.IP=192.168.40.108,192.168.40.109
[Client]
Paste.Allowed=true
thanks for any help