This reminds me of help that foxidrive gave me on an ability to change values within text files with batch that generates a QBasic program and then calls that QBasic program to do stuff that batch alone wasnt able to do. Here is the problem I had that is archived here that worked perfect for changing values within text file based on rules within the QBasic of what to change within the text file.
https://www.computerhope.com/forum/index.php?topic=151160.0;wapThis code here is for my application of changes made by use of QBasic within batch... you could do a similar program to make all changes you need this way as well, but would need to write code that does it. So this is just a working example that works for my needs, but your needs are different.
This solution for my needs replaces two values of N with Y and looks for keywords in the text file and targets them to change them so $LASTSORT N and LS: N are the keywords that it looks for and where found it replaces them with $LASTSORT Y and LS: Y .... My use of this is to force configuration changes to about 50 text files with .mtx and .xts file extensions by use of a Batch file that runs QBasic and targets all TXT files at the target location.
@echo off
set "file=edit.bas"
>"%file%" echo OPEN "temp.tmp" FOR INPUT AS #1
>>"%file%" echo OPEN "temp.txt" FOR OUTPUT AS #2
>>"%file%" echo DO WHILE NOT EOF(1)
>>"%file%" echo LINE INPUT #1, a$: y=1
>>"%file%" echo if not INSTR(ucase$(a$), "LS: N" ) = 0 THEN ? #2, "LS: Y" : y=0
>>"%file%" echo if not INSTR(ucase$(a$), "$LASTSORT N" ) = 0 THEN ? #2, "$LASTSORT Y" : y=0
>>"%file%" echo if y=1 then ? #2, a$
>>"%file%" echo LOOP
>>"%file%" echo CLOSE
>>"%file%" echo SYSTEM
for %%a in (*.mtx *.xts) do (
del temp.txt 2>nul
ren "%%a" temp.tmp
qbasic /run %file%
ren temp.txt "%%a"
)
del temp.txt 2>nul
del %file%
echo done
pause
My thoughts on this is that you will need to use QBasic or another language to achieve what you want to do, but by which that can be called within the batch file if it needs to be a batched process. I didnt think I had a solution for what i needed because the system that runs this is on old NT4 OS and I am not permitted to bringing in any 3rd party media/software etc to work. I was limited to whatever i could type into a text editor, so i had to manually create this on the system that it was to run on since there is a #1 rule that no software comes and goes on media, and rule doesnt apply to manually coding up locally which is virus/malware free. So I manually coded it up at the system that was to run this. You likely dont have restrictions and so your not stuck with only Qbasic etc and it could be achieved in a number of programming language and higher level scripting ways.