Jump to content

Fast compare between two text files


Go to solution Solved by Nine,

Recommended Posts

Hello

1.txt =

33004: SPI
33005: SPPO
33006: VISQ
33007: BRI
33007: BIG
33117: TOR
33118: TOR 50
33120: DA
33122: TA 320
33122: 320
33407: TISK
33408: A 150
33410: TIKA
33413: TISKA 32 P

==============

2.txt = 

33004
30001
33007
33117
33118
30010
30510
 

==============

i need the Common result =

33004
33007
33117
33118

 

(FileReadLine is so slow when i have 3000 line)

Edited by ahmeddzcom
Link to comment
Share on other sites

i use this but i can't get result

#Include <Misc.au3>
#include <File.au3>
#include <StringConstants.au3>

FileDelete("TAXExxx.txt")
If FileExists("TAXExxx.txt") Then Exit MsgBox(0,"","TAXExxx.txt _ not del")

    Local $P1 = "P1.txt"
    Local $P2 = "P2.txt"

    Local $TX1 = "TX1.txt"
    Local $TX2 = "TX2.txt"
    Local $TX3 = "TX3.txt"

        For $y = 1 to _FileCountLines($P1)

            Local $sStringP1 = FileReadLine($P1, $y)
            Local $sStringP2 = FileReadLine($P2, $y)

;~          MsgBox(0, "", $sStringP1&"_"&$sStringP2)

            For $i = 1 to _FileCountLines($TX1)

;~              MsgBox(0, "",$i)

                Local $sStringTX1 = StringLeft(FileReadLine($TX1, $i), 5)
                Local $sStringTX2 = StringLeft(FileReadLine($TX2, $i), 3)

;~              MsgBox(0, "",$sStringTX1&"_"&$sStringTX2&"_____"&FileReadLine("TX3.txt", $i))

                If $sStringP1&"_"&$sStringP2 = $sStringTX1&"_"&$sStringTX2 Then
;~                  MsgBox(0,"",$sStringP1&"_"&$sStringP2)
;~                  FileWrite("TAXExxx.txt",$sStringP1&"_"&$sStringP2&"_____"&FileReadLine("TX3.txt", $i)&@CRLF)


            FileWrite("TAXExxx1.txt",$sStringP1&@CRLF)
            FileWrite("TAXExxx2.txt",$sStringP2&@CRLF)
            FileWrite("TAXExxx3.txt",FileReadLine("TX3.txt", $i)&@CRLF)


                EndIf
            Next
        Next

        Beep(2000,200)

 

Link to comment
Share on other sites

  • Solution

Or :

#include <Array.au3>

Local $t1 = FileRead("T1.txt")
Local $t2 = FileRead("T2.txt")
$t2 = StringReplace($t2, @CRLF, "|")
$a = StringRegExp($t1,"(" & $t2 & ")", 3)
$a = _ArrayUnique($a)
_ArrayDisplay($a)

It could be done in a single line :P

$a = _ArrayUnique(StringRegExp(FileRead("T1.txt"), "(" & StringReplace(FileRead("T2.txt"), @CRLF, "|") & ")", 3))

 

Edited by Nine
Link to comment
Share on other sites

Hi @Nine,

the idea of replacing \r\n with a "|" pipe for using in the RegEx pattern is quite awesome, I like it 👍 .

For the file examples of @ahmeddzcom, absolutly valid and nice, as long as the file will not contain a pipe.
Then it could come to an invalid verification 🤔 .

Anyway, I am impressed because I did such things in a way more complex style in the past, which is obviously not needed 😀 .

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Hi @Nine,

this depends more on the line width (amount of characters on the line).
I tested it with around 3k lines and after two seconds the result is displayed.

If I increase the line width to do a harder comparison it will take several times longer.
But still okay in my opinion 😅 .

Best regards
Sven

________________
Stay innovative!

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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...