Search code examples
batch-filejrepl

Replace text in file using JREPL.BAT


My batch script is supposed to replace content within a file or list of files, but doesn't work and unfortunately exits cycle loop...

Here the code:

@echo off
setlocal enabledelayedexpansion
set "int=000"
set "int_new=111"
for %%i in ("c:\text.txt") do (
    jrepl "!int!" "!int_new!" /m /f "c:\text.txt" /o "c:\text_2.txt"
)
pause

It replaces the text but exit the script, could you explain where my mistake is?


Solution

  • Because JREPL is a separate script from your script, when you run JREPL directly like that, the flow of your script transfers to JREPL and terminates when JREPL does.

    If you want to come back to your script once the replacement is complete, use call jrepl instead.