asiawatcher

how to join x2 text files and display the common entries ?

2 posts in this topic

#1 ·  Posted (edited)

i got x1 text file like this 1,2,3,4,5,6,7,8,9,10, 2,5,10,11,12,2,2,2,10,10

 

how can i SORT this and only display THE numbers that appear one or more times (just display the duplicates, ONCE)

like, it should display 2,5,10 those are the duplicates

should i use arrays ?

except this (which merges all entries) i don't know what to do next. I do not want to remove the duplicates i want to display just them ! cheers

 

Local $txt = "3" &@crlf& "1" &@crlf& "2" &@crlf& "3 " &@crlf& "4" &@crlf& "41" &@crlf& "42" &@crlf& "3" &@crlf& "5" &@crlf& "6" &@crlf& "42"

;Local $txt = FileRead("1.txt") & @crlf & FileRead("2.txt") & @crlf & FileRead("3.txt")

Local $uniq = StringRegExp($txt, "(?s)\b(\d+)\b(?!.*\b\1\b)", 3)

; sorting numeric
Local $temp, $loop = 1
While $loop 
    $loop = 0
    For $i = 1 To UBound($uniq) - 1
        If Number($uniq[$i]) < Number($uniq[$i-1]) Then  ; sort ascending
            $temp = $uniq[$i]
            $uniq[$i] = $uniq[$i-1]
            $uniq[$i-1] = $temp
            $loop = 1
        EndIf
    Next
WEnd
_ArrayDisplay($uniq)
Msgbox(0,"", _ArrayToString($uniq, ", ") )

 

 

 

Edited by asiawatcher

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Added a "Find Duplicate routine" to your example of post #1.

#include <Array.au3>

Local $txt = "3" &@crlf& "1" &@crlf& "2" &@crlf& "3 " &@crlf& "4" &@crlf& "41" &@crlf& "42" &@crlf& "3" &@crlf& "5" &@crlf& "6" &@crlf& "42"
;Local $txt = "1,2,3,4,5,6,7,8,9,10, 2,5,10,11,12,2,2,2,10,10 "
;Local $txt = FileRead("1.txt") & @crlf & FileRead("2.txt") & @crlf & FileRead("3.txt")

Local $uniq = StringRegExp($txt, "(?s)\b(\d+)\b(?!.*\b\1\b)", 3)

; sorting numeric
Local $temp, $loop = 1, $Duplicates = ""
While $loop
    $loop = 0
    For $i = 1 To UBound($uniq) - 1
        If Number($uniq[$i]) < Number($uniq[$i - 1]) Then ; sort ascending
            $temp = $uniq[$i]
            $uniq[$i] = $uniq[$i - 1]
            $uniq[$i - 1] = $temp
            $loop = 1
        EndIf
    Next
WEnd
_ArrayDisplay($uniq)

; --------- Find Duplicate routine -------
For $i = 1 To UBound($uniq) - 1
    StringRegExpReplace($txt, "\b(" & $uniq[$i] & ")\b", "")
    If @extended > 1 Then $Duplicates &= $uniq[$i] & ", "
Next
; ---- End of Find Duplicate routine -----

MsgBox(0, "", "Unique: " & _ArrayToString($uniq, ", ") & @CRLF & _
        "Duplicates: " & StringTrimRight($Duplicates, 2))

And another "Find Duplicate routine"

; --------- Find Duplicate routine -------
Local $a = StringRegExp($txt, "(?s)\b(\d+)\b(?=.*\b\g-1\b)", 3)
Local $dupl = _ArrayUnique($a, 0, 0, 0, 0, 0)
; ---- End of Find Duplicate routine -----

MsgBox(0, "Method 2 (No loop)", "Unique: " & _ArrayToString($uniq, ", ") & @CRLF & _
        "Duplicates: " & _ArrayToString($dupl, ", "))

 

Edited by Malkey
Added another routine.
1 person likes this

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