User to user discussion and support for UltraEdit, UEStudio, UltraCompare, and other IDM applications.

Two- and three-way text compare and merge issues.
3 posts Page 1 of 1
Can I use UltraCompare to create a consolidated listing of un-duplicated items from the lists in two existing files? Specifically, I have two large files, each containing a list of items of less than one line length each. List 1 is 580 lines long and List 2 is 380 lines long. What I want to do is compare the files, eliminate any duplicates, and produce a third file containing only the unique list items from the two files.

Can UC assist me in compiling the consolidated list of the unique items from each of the two lists as a third file on at least a somewhat automated basis?

Thanks,

-Danny.
It is possible to

  1. compare 2 text files with UltraCompare,
  2. click in toolbar on the unequal symbol to see just the differences,
  3. click into pane of file 1 and press Ctrl+A to select all displayed lines only (the unique lines in first file),
  4. copy the selected lines with Ctrl+C to clipboard and paste them into a new file in a text editor,
  5. click into pane of file 2 and press Ctrl+A to select all displayed lines only (the unique lines in second file),
  6. copy the selected lines with Ctrl+C to clipboard and paste them into a new file in a text editor.
But for a completely automated file comparison with getting all unique lines of both files into a new file, it is better to use UltraEdit/UEStudio with a macro or script for this task. See Odd comparison results for short lines with very similar data containing links to several other topics with macros and scripts for this or similar tasks.

The first link listed there is to Compare two files line by line and get not matching lines into two new files.

As you want all unique lines just in a single new file, here is first script from referenced topic with the small modifications necessary for a single file result.

Open in UltraEdit the two files. Create a new ASCII file with DOS line terminators and copy & paste the following script code into this new file. Save the new file with a name like GetUniqueLinesFromTwoFiles.js. Run the script via Scripting - Run Active Script.

Code: Select all
if (UltraEdit.document.length > 1)  // Are at least 2 files opened?
{
   // Define environment for the script.
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();

   // Get all lines from first (most left) file.
   UltraEdit.document[0].selectAll();
   var asLinesFileA = UltraEdit.document[0].selection.split("\r\n");
   // Remove last element from the array if it is an empty string
   // because the file ended with a DOS line termination.
   if (asLinesFileA[asLinesFileA.length-1] == "") asLinesFileA.pop();

   // Get all lines from second file.
   UltraEdit.document[1].selectAll();
   var asLinesFileB = UltraEdit.document[1].selection.split("\r\n");
   if (asLinesFileB[asLinesFileB.length-1] == "") asLinesFileB.pop();

   // Remove the lines existing in both files.
   for (var nLineA = 0; nLineA < asLinesFileA.length; nLineA++)
   {
      var sLineA = asLinesFileA[nLineA];
      for (var nLineB = 0; nLineB < asLinesFileB.length; nLineB++)
      {
         if (asLinesFileB[nLineB] == sLineA)
         {
            asLinesFileB.splice(nLineB,1);
            asLinesFileA.splice(nLineA,1);
            nLineA--;
            break;
         }
      }
   }
   UltraEdit.selectClipboard(9);
   // Are unique lines from file A remaining, write them to a new file.
   var bNewFileCreated = false;
   if (asLinesFileA.length > 0)
   {
      UltraEdit.newFile();
      UltraEdit.clipboardContent = asLinesFileA.join("\r\n") + "\r\n";
      UltraEdit.activeDocument.paste();
      bNewFileCreated = true;
   }
   // Are unique lines from file B remaining, write them to same new file.
   if (asLinesFileB.length > 0)
   {
      if(!bNewFileCreated) UltraEdit.newFile();
      UltraEdit.clipboardContent = asLinesFileB.join("\r\n") + "\r\n";
      UltraEdit.activeDocument.paste();
   }
   if(bNewFileCreated) UltraEdit.activeDocument.top();
   UltraEdit.clearClipboard();
   UltraEdit.selectClipboard(0);
}
Best regards from Austria
Mofi -

Thanks very much, that did the trick. I appreciate it very much.
- Danny, W6SO
www.dannyweiss.net
E-mail Contact - www.dannyweiss.net/contact
3 posts Page 1 of 1
cron