I'm trying to create a bat file that I can pass one parameter to that will get written to a text file in a very specific location in the file. The location in the file is unknown from the beginning where it is, but it can be found using hardcoded values.
The structure of the text file:
SECTION1
value1 = 123456
value2 = asdf
value3 = 1111
SECTION2
value1 = 654321
value2 = something
value3 = 875
SECTION3
value1 = 92948
value2 = aaaaaaa
value3 = 6499
The goal is to call the batch file in this manner:
batch.bat somethingelse
... and then have it update exactly and only SECTION2, value2 from "something" to "somethingelse". Like I wrote, I'm perfectly happy to hardcode "SECTION2" and "value2" in the batch file.
This is what I have so far. It's not much. The way I'm approaching it is in three steps, but perhaps this is the wrong way of looking at it:
1: Identify where SECTION2 starts:
for /f "delims=:" %%N in ('findstr /n "SECTION2" "file.txt"') do set section=%%N
echo %section%
2: From the start of %section% find the first occurrence of value2 and store that row number:
Not sure how to accomplish this.
3: At the final row number, overwrite it with "value2 = " + somethingelse, i.e. the first parameter:
This gives me what the row should look like, but I'm not sure how to actually write it.
set output=value2 = %1
echo %output%