Jump to content
Sign in to follow this  
dmollico

search each line in an array with another array

Recommended Posts

dmollico

I want to take 2 txt files (most likely csv) and take part of each line from text1.csv, and search the entire file of text2.csv for that line.

example files:

text1.csv

7112320093|715|202|54724

7152034293|715|202|54724

text2.csv

7112320093|71532

7158769293|71567

I just want the script to take each line up to the pipe | in text1.csv and search for a match in text2.csv. If it finds one, then spit out the entire line into matches.csv. So in the above example, it would see the first line in text2.csv, but not the second and write the entire first line 7112320093|715|202|54724

to the matches.csv.

I know I need to read each file into an array... I'm just a little lost on how to pull all that together :D

Thanks in advance for any ideas guys!

Dave

Share this post


Link to post
Share on other sites
PsaltyDS

I want to take 2 txt files (most likely csv) and take part of each line from text1.csv, and search the entire file of text2.csv for that line.

example files:

text1.csv

7112320093|715|202|54724

7152034293|715|202|54724

text2.csv

7112320093|71532

7158769293|71567

I just want the script to take each line up to the pipe | in text1.csv and search for a match in text2.csv. If it finds one, then spit out the entire line into matches.csv. So in the above example, it would see the first line in text2.csv, but not the second and write the entire first line 7112320093|715|202|54724

to the matches.csv.

I know I need to read each file into an array... I'm just a little lost on how to pull all that together :D

Thanks in advance for any ideas guys!

Dave

Generate both arrays with _FileReadToArray().

Loop through the first array and use simple string manipulation or StringRegExp() to get the first part.

Use _ArraySearch() to find the string in the second array, being sure to set $iPartial = 1.

Post your code if you get stuck.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dmollico

It's messy, It's ugly - but I believe it works!

#include <File.au3>
#Include <Array.au3>
Dim $aRecords
Dim $bRecords
Dim $searchstring
Dim $arrayresults
Global $File1 = "customer.txt"
Global $File2 = "dncl.txt"
If Not _FileReadToArray($File1, $aRecords) Then
    MsgBox(4096, @ScriptName, "There was an error reading file!")
    Exit
EndIf
;_ArrayDisplay($aRecords, "Array:arecords")
If Not _FileReadToArray($File2, $bRecords) Then
    MsgBox(4096, @ScriptName, "There was an error reading file!")
    Exit
EndIf
;_ArrayDisplay($bRecords, "Array:brecords")

For $j = 1 To $aRecords[0]
    $searchstring = StringLeft($aRecords[$j], 10 )
   ;MsgBox(1,"test",$searchstring)
   $arrayresults = _ArraySearch($bRecords,$searchstring,0,0,0,1,1,0)
   ;MsgBox(1,"test",$arrayresults)
   If $arrayresults > 0 Then
       MsgBox(1,"test",$bRecords[$arrayresults] & " matches " & $aRecords[$j])
       
   EndIf
   Next

Share this post


Link to post
Share on other sites
dmollico

The purpose of this is to search the do not call list with a list of customer phone numbers and their portfolio number.

Yes folks, the data above is fake and isn't real account information :D

I plan on wrapping this into a pretty gui with the ability to search just 1 phone number or a csv.

Share this post


Link to post
Share on other sites
PsaltyDS

The purpose of this is to search the do not call list with a list of customer phone numbers and their portfolio number.

Yes folks, the data above is fake and isn't real account information :D

I plan on wrapping this into a pretty gui with the ability to search just 1 phone number or a csv.

If this database is anticipated to grow to any size at all, you should consider getting off the CSV files and working with a proper DB engine. SQLite fits in nicely with AutoIt.

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
dmollico

I generally utilize mysql with my php intranet and have built a lot of databases off that.

This will be an application to check quarterly files from do not call lists. It is just a 1 time compairison.

thank you for the idea though.

I've completed the gui for this now - so pretty!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×