I am making a batch script that retrieves a file from one location, and copies it to another, and then renames it to autoexec.cfg to fix a problem with a game. The only potential conflict I face is if a user has already created an autoexec.cfg file. So, I need to make my script parse the info from within the target file, and insert it into the very top of an existing autoexec.cfg file if it's present. I know how to replace text using findstr, but I need something like inserting text into a specific location using line and column placement. Here is my current script:
IF NOT EXIST "%LOCALAPPDATA%\ElDewrito\keys.cfg" goto :NOKEYS
IF EXIST "AutoExec.cfg" goto :HASKEYS
IF EXIST "%LOCALAPPDATA%\ElDewrito\keys.cfg" goto :EXECUTE
:NOKEYS
SET msgboxTitle=Error
SET msgboxBody=You don't have any keys to import!
SET tmpmsgbox=%TEMP%\Message.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WSCRIPT "%tmpmsgbox%"
goto :END
:HASKEYS
SET msgboxTitle=Error
SET msgboxBody=You've already imported your keys.
SET tmpmsgbox=%TEMP%\Message.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WSCRIPT "%tmpmsgbox%"
goto :END
:EXECUTE
COPY "%LOCALAPPDATA%\ElDewrito\keys.cfg" ".\AutoExec.cfg"
goto :SUCCESS
:SUCCESS
SET msgboxTitle=Import
SET msgboxBody=Keys successfully imported!
SET tmpmsgbox=%TEMP%\Message.vbs
IF EXIST "%tmpmsgbox%" DEL /F /Q "%tmpmsgbox%"
ECHO msgbox "%msgboxBody%",0,"%msgboxTitle%">"%tmpmsgbox%"
WSCRIPT "%tmpmsgbox%"
goto :END
:END
Is it possible to parse/copy strings from one text-based document, and paste it into another at a specific position to avoid breaking the structure of the second document? I am aware that the Exchanges aren't for solving one's problems, I just need an idea of if this is feasible, and how to implement it.