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

Two- and three-way text compare and merge issues.
2 posts Page 1 of 1
I've been trying to use the programmatic/command line approach to comparison with UltraCompare. If I start out with a text file containing the text:

comply with the requirement after 91 days, the hospital’s accreditation decision will be

And Do a compare against the .txt file containing the text:

comply with the requirement after 90 days, the hospital’s accreditation decision will be

As you can see, the difference is "91" to "90" days. The output file always gives me something like this:

Code: Select all
1       *       comply with the requirement after 91 days, the hospital’s accreditation decision will be
        *       comply with the requirement after 90 days, the hospital’s accreditation decision will be

This is fine, I want the entire text being compared, but I really really need to know where in the text the change has occurred. Is there a switch that I can use to mark the changes? That way it would spit out something like this instead:

Code: Select all
1       *       comply with the requirement after 9*1 days, the hospital’s accreditation decision will be
        *       comply with the requirement after 9*0 days, the hospital’s accreditation decision will be

As you can see, it marks the location of the difference with an asterik too. Is there a way to mark the output? Any way I can know where in the text it has changed? Any and all suggestions are much appreciated. Thank you for reading and for your suggestions.
No, there is no option in UltraCompare to get the result you want. But if you uncheck at Configuration - Backup & Save the option Save result in Unicode to save the results in an ANSI file, you can call UltraEdit to do that after UltraCompare has produced the result file. You will need the command line:

start "Mark Differences" /wait "C:\Program Files ...\uedit32.exe" /fni /s,e="full name of script file" "full name of result file produced by uc"

You don't need start "Mark Differences" /wait if this is the last line in your batch file which runs UltraCompare. You maybe want to add /min after /wait to run UE minimized.

The code for the script file I have developed for you is:

Code: Select all
// That script works only for ASCII/ANSI files, not Unicode files!
if (UltraEdit.document.length > 0) {
   UltraEdit.ueReOn();  // Use UltraEdit regular expression engine.
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   UltraEdit.activeDocument.hexOff();
   UltraEdit.activeDocument.top();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=false;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchAscii=false;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.searchInColumn=false;
   // Search for lines starting with a line number, followed by a
   // tab character, an asterisk, a space and a further tab character.
   while (UltraEdit.activeDocument.findReplace.find("%[0-9]+^t+^* ^t")) {
      // Line found, remember the current line number.
      var nLineNumber = UltraEdit.activeDocument.currentLineNum;
      // Select the rest of the line including line ending.
      UltraEdit.activeDocument.findReplace.find("?++^p");
      // Store that string in a string variable.
      var sFirstLine = UltraEdit.activeDocument.selection;
      // Ignore the spaces and tabs at beginning of next line and
      // select the rest of the line including the line ending.
      UltraEdit.activeDocument.findReplace.find("[~ ^t*]+?++^p");
      // Store that string also in a string variable.
      var sSecondLine = UltraEdit.activeDocument.selection;
      var nLineLength1 = sFirstLine.length;
      var nLineLength2 = sSecondLine.length;
      var nCharIndex = 0;
      // Compare the 2 lines (strings) and break the loop on first different character.
      while (nCharIndex < nLineLength1 && nCharIndex < nLineLength2) {
         if (sFirstLine.charAt(nCharIndex) != sSecondLine.charAt(nCharIndex) ) break;
         nCharIndex++;
      }
      // Add default number of columns before line string starts. The tab chars are interpreted
      // with a tab stop value of 8 and so the original lines start at column seventeen.
      nCharIndex += 17;
      // Insert in both lines on first different character a # as marker.
      UltraEdit.activeDocument.gotoLine(nLineNumber,nCharIndex);
      UltraEdit.activeDocument.write("#");
      UltraEdit.activeDocument.gotoLine(nLineNumber+1,nCharIndex);
      UltraEdit.activeDocument.write("#");
   }
   UltraEdit.closeFile(UltraEdit.activeDocument.path,1);
}

This script inserts # in both lines left to first different character. The character comparison is done case-sensitive.
Best regards from Austria
2 posts Page 1 of 1
cron