How to find duplicates in two different tables

How to find duplicates in two different tables

5

    9:55 - Nov 25#1

    I need to find duplicates in two different XML files named table6.xml and table32.xml.

    table6.xml has a line:

    Code: Select all

    <c1>6932</c1>
    table32.xml has this line

    Code: Select all

    <c12>6442</c12>
    I want to know if 6932 exists in both files.

    I know that there are 124 duplicates.

    How to?

    I tried to upload the two files, but they were rejected.

    Best regards

    Edvard Korsbæk

    6,684586
    Grand MasterGrand Master
    6,684586

      18:47 - Nov 25#2

      There are a lots of scripts and macros posted for finding duplicate lines of two files or the opposite finding unique lines of two files, see the results of the advanced forum search +duplicate* +file* in the macros and scripts forums.

      If the forum prevents uploading *.xml files, compress both into a 7-Zip (*.7z), RAR (*.rar) or ZIP (*.zip) archive file and attach the archive file to the post.
      Best regards from an UC/UE/UES for Windows user from Austria

      5

        10:12 - Nov 26#3

        Dear Mofi!

        I ended up by using ChatGTP to make this script in PowerShell. I am 79 years old, and to lean another programming language is perhaps a bit late.

        Code: Select all

        # Filepaths
        $file1 = "d:\ada\roenberg\table6.xml"
        $file2 = "d:\ada\roenberg\table32.xml"
        
        # Read the content of the XML-files
        [xml]$xml1 = Get-Content $file1
        [xml]$xml2 = Get-Content $file2
        
        # Get values from the specifikke tags
        $c1Numbers = $xml1.SelectNodes("//c1") | ForEach-Object { $_.InnerText }
        write-output "tabel6:  $c1Numbers"
        $c12Numbers = $xml2.SelectNodes("//row/c12") | ForEach-Object { $_.InnerText }
        write-output "tabel32:  $c12Numbers"
        # Find duplicates
        $commonNumbers = $c1Numbers | Where-Object { $c12Numbers -contains $_ }
        
        # Write out.
        Write-Output "Fælles numre: $($commonNumbers.Count)"
        $commonNumbers | Sort-Object