Jump to content

Delete matches on 2 file lists


DrewSS
 Share

Go to solution Solved by mikell,

Recommended Posts

Hello,

I've done some concatenation on several excel docs to build 2 unique lists. However, I need take it 1 step farther and get a list of the UniqueMasterList.txt entries that do NOT match any entries in the Existing.txt file.

Can someone please point me in the right direction or show me how this may be done?

 

Existing.txt

UniqueMasterlist.txt

Edited by DrewSS
Link to comment
Share on other sites

  • Moderators

I would think using a sqlite database, making a unique column for the data you need to be unique would be simplest.

This way, only unique data could be entered without the need for tireless looping with a regex or stringsplit method.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

#include <Array.au3>

Local $aListUnique = StringSplit("111-111,222-222,333-333,444-444,555-555,666-666,777-777",",")
Local $aListExisting = StringSplit("111-111,333-333,444-444,555-555,777-777",",")


_ArrayDisplay($aListUnique)
_ArrayDisplay($aListExisting)


Local $i, $i2

For $i = 0 to $aListUnique[0]
    For $i2 = 0 to $aListExisting[0]
        If $aListExisting[$i2] = $aListUnique[$i] Then
            $aListUnique[$i] = ""
            ExitLoop
        EndIf
    Next
Next

_ArrayDisplay($aListUnique)

If I understand your question correctly, this would be the cumbersome method.  But I get the feeling time isn't of the essence, and this would "get the job done".  Any matches found in the Existing array are replaced with "".

Edited by kaisies
Link to comment
Share on other sites

  • Solution

FileReadToArray then Scripting.Dictionary is the best way

#include <Array.au3>

Local $a[11] = [1, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12]
Local $b[12] = [1, 2, 2, 3, 4, 5, 6, 8, 10, 12, 13, 14]

Local $sda = ObjCreate("Scripting.Dictionary")
Local $sdb = ObjCreate("Scripting.Dictionary")

For $i In $a
    $sda.Item($i) 
Next
For $i In $b
    $sdb.Item($i)
Next
For $i In $sdb
    If $sda.Exists($i) Then $sdb.Remove($i)
Next
$asd = $sdb.Keys()

_ArrayDisplay($asd, "$asd")
Link to comment
Share on other sites

Thank you both very much! 

I've never heard of Scripting.Dictionary but it looks promising. I'm going to try this today!

For the StringSplit method, is there an easy way to import each line of the text files as a separate string? 

And Sm0Ke_N; excellent suggestion, but the users of this wont have sql installed on their PCs so I need to keep it isolated -- like kaisies said, cumbersome isnt an issue here, its just gotta work. The Excel concatenation already takes 90 - 180 seconds (15000 + rows, 8-12 columns per report, 5x excel reports )  

Link to comment
Share on other sites

 

FileReadToArray then Scripting.Dictionary is the best way

#include <Array.au3>

Local $a[11] = [1, 1, 3, 5, 6, 7, 8, 9, 10, 11, 12]
Local $b[12] = [1, 2, 2, 3, 4, 5, 6, 8, 10, 12, 13, 14]

Local $sda = ObjCreate("Scripting.Dictionary")
Local $sdb = ObjCreate("Scripting.Dictionary")

For $i In $a
    $sda.Item($i) 
Next
For $i In $b
    $sdb.Item($i)
Next
For $i In $sdb
    If $sda.Exists($i) Then $sdb.Remove($i)
Next
$asd = $sdb.Keys()

_ArrayDisplay($asd, "$asd")

Wow that was perfect. Thank you so much!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...