1

A user defined input file has to be integrated into the entries of pre-set output file, changing the data at a given block [A-Z] and index [1-75] position.

The input file structure with wildcards for variable parts:

* 00asr[1-75] 00asr*
b -v -o 00asr34 00asr34.hkx (example)
b -v 00asr35 00asr35.hkx (example)

Output file as above but with multiple blocks [A-Z]asr[1-75]:

* Aasr[1-75] Aasr*
* Basr[1-75] Basr*
  ...
* Zasr[1-75] Zasr*

The user has to pick a given letter A-Z to determine parts of the string and the block to replace information in. Then we can replace the %input% substrings 00asr with %block%asr; they will then match given substrings in the %output%: * 00asr[1-75] 00asr* >> * Zasr[1-75] Zasr* in the case of Z.

@ECHO OFF
ECHO INPUT FILE:
ECHO %1
SET INTEXT=%1
ECHO.
SET /P "LETTER=Letter? "
SET "REPLACE=%LETTER%asr"
SET TMP=tmp.txt

setlocal enabledelayedexpansion

FOR /F "tokens=1,* delims=¶" %%A IN ( '"TYPE %INTEXT%"') DO (
SET string1=%%A
SET modified=!string1:00asr=%REPLACE%!
echo !modified! >> %TMP%
)
PAUSE

I adapted this code. Looks like good code to me, but I'm like a blind man.

Now either the %TMP%s first-line [1-75] is required to determine whether there is any offset in the block or the strings have to be compared, overwriting the line containing substring * Zasr[1-75] Zasr* with the same one from %TMP%; or in the case of offset skipping a given amount of lines in %output% before overwriting the lines. I'm not sure which option would be easier to implement or quicker to execute, since I'm entirely failing at doing this.

The whole method should work something like this:

Input File

o <parameters> 00asr3 00asr3.hkx
o <parameters> 00asr4 00asr4.hkx
o <parameters> 00asr5 00asr5.hkx

User Input Q

OUTPUT BEFORE

...
p Oasr75 Oasr75.hkx

p Qasr1 Qasr1.hkx
p Qasr2 Qasr2.hkx
p Qasr3 Qasr3.hkx
p Qasr4 Qasr4.hkx
p Qasr5 Qasr5.hkx
p Qasr6 Qasr6.hkx
....

OUTPUT AFTER

...
p Oasr75 Oasr75.hkx

p Qasr1 Qasr1.hkx
p Qasr2 Qasr2.hkx
o <parameters> Qasr3 Qasr3.hkx
o <parameters> Qasr4 Qasr4.hkx
o <parameters> Qasr5 Qasr5.hkx
p Qasr6 Qasr6.hkx
....

I managed to write the file renaming parts just fine; but this... I don't even. I have been looking at various articles but due to not actually knowing any batch I'm not getting ahead with this.

1 Was very helpful, but I outright fail to compare strings correctly and can't seem to manage to assign them to variables.

Any help is appreciated. I might even understand what I'm doing wrong (which currently is most things).

Community
  • 1
  • 1

1 Answers1

0

I've solved it by myself. Here's a shortened version of the script. Cleaning input somewhat, changing the token in tmp, getting target parameters, removing old target strings from file, merging files, deleting temps. I'm confident this code isn't very good either way so further explanation seems unnecessary.

@ECHO OFF
SET _PACK=%1
SET "PATH=%~dp0"
SET "_LIST=in.txt"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "_ERROR=0"
:USERINPUT
IF %_ERROR%==1 (
ECHO INVALID INPUT: string too long.
SET "_ERROR=0"
)
IF %_ERROR%==2 (
ECHO INVALID INPUT: non-letter.
SET "_ERROR=0"
)
SET /P "LETTER=ENTER NEW BLOCK LETTER A-Z: "
ECHO "%LETTER%" SELECTED
IF NOT "%LETTER:~1,1%"=="" (
SET "_ERROR=1"
GOTO USERINPUT
)
if "%LETTER%" lss "A" (
SET "_ERROR=2"
GOTO USERINPUT
)
if "%LETTER%" gtr "Z" (
SET "_ERROR=2"
GOTO USERINPUT
)
SET "_STRING=%LETTER%asr"

' renaming files here

SET TMP=asr.tmp
DEL %TMP%
SET "_COUNT=0"
FOR /F "tokens=1,* delims=¶" %%A IN ( '"TYPE %_PACK%"') DO (
SET _LINE=%%A
SET _NEWLINE=!_LINE:0asr=%_STRING%!
ECHO !_NEWLINE!>> %TMP%
CALL SET /A _COUNT=_COUNT+1
)
ECHO NUMBER OF INPUT LINES: !_COUNT!
SET /P _OFFSET=< %TMP%
CALL SET _OFFSET=%%_OFFSET:*asr=%%
CALL SET _OFFSET=%%_OFFSET:~0, 2%%
CALL SET _OFFSET=%_OFFSET: =%
ECHO OFFSET: %_OFFSET%.
SET /A _END=_COUNT+_OFFSET-1
COPY /Y in.txt in.tmp
FOR /L %%X IN (%_OFFSET%, 1, %_END%) DO (
SET "_SEARCH=%_STRING%%%X "
ECHO DELETING OLD STRING : !_SEARCH!
FINDSTR /V /C:"!_SEARCH!" %_PACK% > in.tmp
del in.txt
ren "in.tmp" "in.txt"
)
TYPE %TMP%>> in.txt
DEL %TMP%
PAUSE
DEL %1
EXIT