Batch file edit text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Lignys
Posts: 1
Joined: 06 Sep 2022 00:40

Batch file edit text file

#1 Post by Lignys » 06 Sep 2022 00:54

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?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file edit text file

#2 Post by aGerman » 06 Sep 2022 10:35

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

Post Reply