In this working-session webinar we helped Dimitri with a project he was working on. In short, he is looking for specific text in a “large” text file. We discussed various approaches to the solution and created a few example solutions
Script Highlight: Control panel objects by jNizM
Several things to consider before writing a solution
1.Just how large is/will the text file get?
A.Is the file going to be appended to over time?
2.Do you just need to answer “is the text value in the file” or do you need more information
A.how many occurrences
B.which lines it is on
C.other values related to it (key-value pairs, other fields, etc.)
3.Do you care if the text is found multiple times?
4.How important is speed
5.Would a “fuzzy search” help?
6.Will you be running single or multiple searches?
Possible Approaches for finding text in a large text file
- Use InString on file read (see below example)
- Shove it into an Object (see below example)
- Use built-in ADO database query by VXE
- Use SQLite3
Simple InStr solution
Loop,Read, B:\the-automator\Webinar\Scripts\2020-01-Working Session\Dimitri\glbintf3.dat ;loop over data file (line by line) if InStr(A_LoopReadLine,"ENP-001213") ;If there is a : in the row, then proceed m(A_LoopReadLine,A_Index)
Shoving into an Object
obj:={} ;Create object for storing data Loop,Read, B:\the-automator\Webinar\Scripts\2020-01-Working Session\Dimitri\glbintf3.dat ;loop over data file (line by line) { if InStr(A_LoopReadLine,":"){ ;If there is a : in the row, then proceed RegExMatch(A_LoopReadLine,"(\d+:)(\s+)?(?<Str>\S+.*)",arr_) ;Grab everything to the right of the : and push into Arr_Str obj[arr_Str]:=1 } } ;********************Show all in object*********************************** for k,v in obj output.=k "`n" MsgBox %output% ;********************Loop and find your value*********************************** for k,v in obj{ if(InStr(k,"ENP-003066")) m(k) }