Page 1 of 1

Batch file edit text file

Posted: 06 Sep 2022 00:54
by Lignys
I made a batch file as below referring to other topic.
However, an undesirable result is shown as below, and I think the cause is "=".

[Edit_txt.bat]

Code: Select all

@echo off
set "replace=MAX_SCALE-MARKINGS_VAL=20000"
set "replaced=MAX_SCALE-MARKINGS_VAL=500"

set "source=Source.txt"
set "target=Target.txt"

setlocal enableDelayedExpansion
(
   for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %source%') do (
      set "line=%%b"
      if defined line set "line=!line:%replace%=%replaced%!"
      echo(!line!
   )
) > %target%
endlocal


Source: MAX_SCALE-MARKINGS_VAL=20000
Target(result): 20000=MAX_SCALE-MARKINGS_VAL=500=20000


the result i wanted was: MAX_SCALE-MARKINGS_VAL=500

Can I get some help?

Re: Batch file edit text file

Posted: 06 Sep 2022 10:35
by aGerman
I knew we have a thread about it. I just had to find it.
viewtopic.php?t=1485

Maybe consider to use a 3rd party regex processor or dbenham's JREPL.BAT
viewtopic.php?t=6044

Steffen