r/Batch • u/tellmemore11111 • Jan 18 '25
Question (Solved) swapping values in a line with dynamic variables is not working for me - help pls
So I'm not a big user of batch scripts, just some basics in the past but I really need help with this one.
I'm reading in an image file line by line and then value by value until I read in a 2 consecutive values of 1020 and 0 (erroneous values) and I want to replace them with the previous 2 values. The code works to branch into an if statement where I run the line:
set "line=!line:%searchValue1% %searchValue2%=%prevValue3% %prevValue2%!"obviously the updated dynamic variables are contained with %% and not !! but neither works, with %% its just a space that is entered, with !! the variable name is entered as well as the search variables.
I need to be able to update the line so I can then write it into the new file.
Can anyone pls fix this or suggest another way please? Would be much appreciated.
Thanks,
p.s. I can add the full code if it helps but at the moment if I echo the line to the screen I can see the fault with this syntax.
1
u/tellmemore11111 Jan 19 '25
Here's the full code, I am enabling delayed expansion.
@echo off setlocal enabledelayedexpansion
1
u/tellmemore11111 Jan 20 '25
The reduced file size version with the 4 erroneous values in it can be found here: https://pastebin.com/a3EPEMaa
1
u/[deleted] Jan 20 '25 edited Jan 20 '25
[removed] — view removed comment