Hello all,
I am trying to create a simple batch file that will replace a line in a text file with a different line, but keep every other line in the file the same. I found a script somewhere on the internet which I modified slightly and came up with the following code. However, for some reason this code is not echoing any lines ending in "=0" to the new text file as it should be, and is instead echoing them to screen (even with echo off). Does anyone have any suggestions?
Thanks much.
@echo off
if exist prod.ini del new_prod.ini
for /f "tokens=*" %%a in (prod.ini) do call :AddText "%%a"
del prod.ini
rename new_prod.ini prod.ini
exit /b
:AddText %1
@echo on
echo %1
@echo off
set Text=%~1%
if "%Text%"=="server=server-2.domain.com" (
echo server=server-3.domain.com>> new_prod.ini
) else (
echo %~1%>> new_prod.ini
)
exit /b
The original file has some lines like those that follow, but the new file after the script has left out these lines. The script works exactly as expected on the replace, as well as on 20 or so other lines. Only the lines that look as follows cause problems.
_sflag=0
debug_lvl=0
sel_test_lvl=0
ipc_error_logging_lvl=0
ipc_client_debug_lvl=0
ipc_server_debug_lvl=0
Thanks again.
edit: This will be run on hundreds of computers in the organization and using 3rd party tools is not really an option, as installing another application on all machines (even though theoretically possible with the remote management software we will use) is not desired.
Thanks.