Jump to content

compare 2 txt files


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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