I have a text file which I am trying to edit via a batch script. Concretely speaking, the file contains a list of parameters and I am trying to add a path (string) right after one of the parameters (string as well).
To do so I wrote the script below which is supposed to
- Iterate through each line of the file
- Concatenate the parameter and the path together into a new line if the line contains the parameter I am looking for.
- Output everything (unchanged and changed lines) to a new txt file.
In my case the parameter I am looking for in my file is "image".
Unfortunately, although the main problem here is probably that I am dumb, I have been unable to figure out why it doesn't work and would very much appreciate some help.
Here is the code:
@setlocal enableextensions enabledelayedexpansion
@echo off
push %~dp0
set "path=%UserProfile%"
REM iterate through each line of given txt file
for /F "delims="%%G in (settings.txt) do (
set line =%%G
if not x%line:image=%==x%line% set "newline=%line%%path%
echo !newline! >> newFile.txt
)
popd
pause
exit /b 0
For reference, I based myself on this page to write my code.
Thanks in advance