Reverse or Backward InStr Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JemyM
Posts: 44
Joined: 04 Jul 2017, 11:57

Reverse or Backward InStr

26 Sep 2018, 08:40

I came to a point where I need to do a massive amount of reverse searches and would benefit from a reverse InStr function.

I have a huge text file (a few million lines) with 7z output that looks like the code section below.

In this I need to find files with the same filename or crc, coupled with filesize, then return the name of the .zip.

Lets say I searched for DOOM.EXE (size 709905) here. I would first need to find DOOM.EXE, then find the first occurance of "Size = " after, which is easy. But then I would have to reverse the search to find the first "Listing Archive: " prior. Since there are thousands of "Listing Archive: " prior and after this tiny section of the text file I do not know how I can do it.

Any idea or custom function for this?

Code: Select all

Listing archive: C:\Games\DOOM (1993).zip

--
Path = C:\Games\DOOM (1993).zip
Type = zip
Physical Size = 5531066
Comment = TORRENTZIPPED-826F22B9

----------

Path = DOOM\DMFAQ66D.TXT
Folder = -
Size = 34572
Packed Size = 11768
Modified = 1996-12-24 23:32:00
Created = 
Accessed = 
Attributes = 
Encrypted = -
Comment = 
CRC = 4FB284FF
Method = Deflate:Maximum
Characteristics = 
Host OS = FAT
Version = 20
Volume Index = 0
Offset = 148750

Path = DOOM\DOOM.EXE
Folder = -
Size = 709905
Packed Size = 360317
Modified = 1996-12-24 23:32:00
Created = 
Accessed = 
Attributes = 
Encrypted = -
Comment = 
CRC = BE91C727
Method = Deflate:Maximum
Characteristics = 
Host OS = FAT
Version = 20
Volume Index = 0
Offset = 160674
JemyM
Posts: 44
Joined: 04 Jul 2017, 11:57

Re: Reverse or Backward InStr

26 Sep 2018, 08:55

I realized short after writing this that I could use InStr and search from the "end of string" if I made a substring that ends where the file I searched for begun.

ReadFile, FileCollection, FileCollection.txt

FilenameToSearchFor = doom.exe

FileLocation := Instr(FileCollection,FilenameToSearchFor "`r")
ListingArchive := Instr(SubStr(FileCollection,1,FileLocation),"Listing Archive: ",,0)
MsgBox, % SubStr(FileCollection,ListingArchive,FileLocation-ListingArchive)
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Reverse or Backward InStr  Topic is solved

26 Sep 2018, 11:03

you may also use Regex if you're familiar with it.
the first one maybe a bit faster

Code: Select all

FilenameToSearchFor = doom.exe
RegExMatch(FileCollection, "is)Listing archive:([^L]|L(?!isting archive:))*?" FilenameToSearchFor, m)
MsgBox % m
RegExMatch(FileCollection, "is)(Listing archive:)(.(?!(?1)))*?" FilenameToSearchFor, m)
MsgBox % m
JemyM
Posts: 44
Joined: 04 Jul 2017, 11:57

Re: Reverse or Backward InStr

28 Sep 2018, 10:22

AlphaBravo wrote:you may also use Regex if you're familiar with it.
the first one maybe a bit faster

Code: Select all

FilenameToSearchFor = doom.exe
RegExMatch(FileCollection, "is)Listing archive:([^L]|L(?!isting archive:))*?" FilenameToSearchFor, m)
MsgBox % m
RegExMatch(FileCollection, "is)(Listing archive:)(.(?!(?1)))*?" FilenameToSearchFor, m)
MsgBox % m
I spent a lot of time with this one, and it works great in any checker I try, but the FileCollection text file is about 2 million characters and it seems RegExMatch can't handle that.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 134 guests