This is an easy to achieve task with using JREPL.BAT written by Dave Benham which is a batch file / JScript hybrid to run a regular expression replace on a file using JScript.
@echo off
if not exist "test.txt" goto :EOF
if not exist "%~dp0jrepl.bat" goto :EOF
call "%~dp0jrepl.bat" "(tenant_id *= *)1234" "$1649" /F "test.txt" /O -
The batch file first checks if the file to modify exists at all and immediately exits if this condition is not true, see Where does GOTO :EOF return to?
The batch file JREPL.BAT must be stored in same directory as the batch file with the code above. For that reason the batch file checks next if JREPL.BAT really exists in directory of the batch file and exits if this condition is not true.
The meaning of the regular expression search string is:
(
...)
... Find a string referenced in replace string with $1
to keep this part of found string unmodified starting with
tenant_id
... case-sensitive string tenant_id
*
... with 0 or more spaces
=
... and an equal sign
*
... and once more 0 or more spaces
1234
... and the characters 1234
.
The replace string back-references the found string starting with tenant_id
and ending before number 1234
with $1
and replaces 1234
by 649
.
It would be also possible to use the regular expression \d+
instead of 1234
in search string to find any number with one or more digits.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
... explains also %~dp0
... drive and path of argument 0 which is the batch file path always ending with a backslash.
echo /?
goto /?
if /?
jrepl.bat /?