Batch file trimming?

Programming related discussions related to game research
Doctor Loboto
Posts: 376
Joined: Sun May 31, 2015 2:23 am

Batch file trimming?

Post by Doctor Loboto »

Hey all, I was hoping someone could help me with a little issue I've been having. I have over 200 files, and I want to trim them all up to the first appearance of a specific string. I need a batch file for command prompt, or even quickbms, to do this preferably.
Basically I want to do this for all files.

Go from
"miscellaneousclutterCTPKfollowed"
to
"CTPKfollowed"

Essentially I want to delete everything in the file BEFORE the string "CTPK" appears.

Can anyone help?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Batch file trimming?

Post by aluigi »

something like this, probably you want to "work" on the NAME variable:

Code: Select all

findloc OFFSET binary "CTPK"
get SIZE asize
math SIZE - OFFSET
get NAME filename
log NAME OFFSET SIZE
Doctor Loboto
Posts: 376
Joined: Sun May 31, 2015 2:23 am

Re: Batch file trimming?

Post by Doctor Loboto »

All right, that works. Thanks much. On a minor addendum to this, how would one go about specifying that the SECOND occurrence of a string is the one that needs to be trimmed to? For example:

"miscellaneousdataTGXTmoredataGXTfollowing"
to
"GXTfollowing"?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Batch file trimming?

Post by aluigi »

Replace:

Code: Select all

get SIZE asize
with

Code: Select all

goto OFFSET
findloc SIZE binary "THE OTHER PATTERN YOU WANT TO SEARCH"
math SIZE - OFFSET
It's important that the second pattern is different than the first one or you will find it again, if it's the same it's enough to add a "getdstring DUMMY 4" before the above code to skip the first pattern found.
Doctor Loboto
Posts: 376
Joined: Sun May 31, 2015 2:23 am

Re: Batch file trimming?

Post by Doctor Loboto »

It doesn't seem to be working. Basically what I need to do is delete everything in the file before the EXACT string "GXT" is found, including the "TGXT" being deleted.
Doctor Loboto
Posts: 376
Joined: Sun May 31, 2015 2:23 am

Re: Batch file trimming?

Post by Doctor Loboto »

Ok, one quick question, how would I go about deleting everything up to and INCLUDING the first "3DS-LZ" in a file?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Batch file trimming?

Post by aluigi »

Code: Select all

findloc OFFSET string "3DS-LZ"
math OFFSET + 6
get SIZE asize
math SIZE - OFFSET
log "new.dat" OFFSET SIZE