Jump to content
Sign in to follow this  
myspacee

compare 2 txt files

Recommended Posts

myspacee

hello to all,

i have a request.

i've 2 txt files :

__________ A.txt

111111111111111111

222222222222222222

333333333333333333

999999999999999999

__________ B.txt

111111111111111111

222222222222222222

333333333333333333

444444444444444444

555555555555555555

how compare A with B -> delete dupes lines in A ?

thank you for any suggestions,

m.

Share this post


Link to post
Share on other sites
i542

Global $i = 0
$handleA = FileOpen("filea.txt",1)
$handleB = FileOpen("fileb.txt",1)
If FileRead($handleA) <> FileRead($handleB) Then
   While 1
     $i += 1
     $line1 = FileReadLine ( $handleA, $i )
     If @error Then
       MsgBox(0,"","EoF")
       ExitLoop
     EndIf
     $line2 = FileReadLine( $handleB, $i)
     If $line1 = $line2 Then 
      ;delete the line - I have no idea how :)
     EndIf
   WEnd
EndIf
Not Tested.


I can do signature me.

Share this post


Link to post
Share on other sites
DMEE

Global $i = 0
$handleA = FileOpen("filea.txt",2); erase previous content, instead of deleting the differing lines, copy the matching lines
$handleB = FileOpen("fileb.txt",0)
If FileRead($handleA) <> FileRead($handleB) Then
   While 1
     $line1 = FileReadLine ( $handleA); This improves the performance (see help file)
     If @error Then
       MsgBox(0,"","EoF")
       ExitLoop
     EndIf
     $line2 = FileReadLine( $handleB); This assumes that both files has the text on the same line
     If $line1 = $line2 Then 
       FileWriteLine($handleA, $line1)
     EndIf
   WEnd
EndIf
Not Tested.
The quoted script is somewhat adapted; thanks for the start i542.

It does not delete the lines in the first file, but writes the lines whenever these are the same in the second file.


In the beginning there was nothing and then even that exploded - anonymous

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.