I got this code (in this question) that finds and replaces string but it adds a blank new line at the end of the output file and makes it not usable.
@echo off &setlocal
set "Russian=g_language = Russian"
set "English=g_language = English"
set "textfile=user.cfg"
set "newfile=user.bak"
Call :SwapLang Russian
:search
Color 9B
@echo off&prompt :&mode con cols=60 lines=16
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo PLEASE RUN NOTEPAD
echo.
echo.
echo.
echo.
echo.
:search
TIMEOUT /T 2
TASKLIST|FIND "notepad.exe"
IF %ERRORLEVEL% equ 0 (GOTO found) ELSE (GOTO search)
:found
Call :SwapLang English
Goto :Eof
:SwapLang %1 byRef
( for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal EnableDelayedExpansion
If /I "!line:~0,12!" Equ "g_language =" (
echo(!%1!
) Else (
echo(!line!
)
endlocal
)) > "%newfile%"
del %textfile%
rename %newfile% %textfile%
Goto :Eof
INPUT FILE: It has 6 line with no blank line.
sys_usefrontline = 1
net_frontline_address = s1.gmru.net
net_frontline_port = 5050
g_language = Russian
cl_promoPageWidth = 820
cl_promoPageHeight = 726
OUTPUT1 FILE: It has 7 lines, last line is blank (can't be shown here).
sys_usefrontline = 1
net_frontline_address = s1.gmru.net
net_frontline_port = 5050
g_language = Russian
cl_promoPageWidth = 820
cl_promoPageHeight = 726
OUTPUT2 FILE: It has 7 lines, last line is blank(can't be shown here).
sys_usefrontline = 1
net_frontline_address = s1.gmru.net
net_frontline_port = 5050
g_language = English
cl_promoPageWidth = 820
cl_promoPageHeight = 726
Could someone help me with this?