Keyed file compare

Keyed file compare

26
Basic UserBasic User
26

    Jul 22, 2006#1

    Is there a way to specify a key to the files being compared and have UC compare rows with matching keys and just denote rows that are missing or new for unmatched keys?

    I know that the flat files are not really keyed, but I'm hoping there is a way tell UC to consider certain positions on a line as the "KEY".

    I'll try to explain via this example:

    Code: Select all

        1st  file                2nd  file
    --- columns -------      --- columns -------
    1-6           7-end      1-6           7-end
    key           text       key           text
    1             abc        1             cba
    2             def        *** No matching key
    *** No matching key      3             369
    :?:
    tia,
    Billy

    6,668580
    Grand MasterGrand Master
    6,668580

      Aug 08, 2006#2

      No, this is not possible.

      But I have written for you an UltraEdit macro which maybe creates the result you want. It's an extended variant of the macro described at How do I remove duplicate lines?.

      You must have the 2 files opened in UltraEdit. First it copies to content of the current file and pastes it at top of the previous file and inserts a line with » as marker to divide the 2 contents of the files.

      Then all trailing spaces and blank lines are removed and the last line is also terminated with a CRLF if the line termination is missing at the last line. Next all lines are marked at start of the line with a special marker string. See the linked thread why.

      The following first main loop deletes all lines which are 100% identical.

      The second main loop deletes all unique lines from first file and marks all lines where the string of column 1-6 is identical (but not the rest).

      Next all lines with unmodified start of line marker string are deleted because they are unique in the second file.

      Last all the markers are removed and the file is sorted. The result is a file which contains only the lines where column 1-6 are identical but not the rest. The last command opens the Save As dialog to store the results file with a different name to avoid destroying the content of the current file.

      I could rewrite the macro to produce a different result format if you want it not in this simplified format.

      Enable the macro property Continue if a Find with Replace not found for this macro. The macro is written for ASCII DOS files and not Unicode/UTF-8 files or files with UNIX/MAC line endings without permanent or temporary conversion to DOS!

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Clipboard 9
      SelectAll
      Copy
      EndSelect
      Top
      PreviousWindow
      Top
      Paste
      IfColNumGt 1
      "

      "
      Else

      "
      EndIf
      TrimTrailingSpaces
      Loop
      Find "^p^p"
      Replace All "^p"
      IfNotFound
      ExitLoop
      EndIf
      EndLoop
      Bottom
      IfColNum 1
      Else
      "
      "
      EndIf
      Top
      Find RegExp "%^([~^p]^)"
      Replace All "#MOFI_RULES#^1"
      Find "#MOFI_RULES#»"
      Replace "»"
      Top
      Loop
      IfCharIs "»"
      ExitLoop
      EndIf
      StartSelect
      Key END
      Cut
      EndSelect
      Find MatchCase "^c^p"
      Replace All ""
      IfNotFound
      Paste
      Key HOME
      Key DOWN ARROW
      Else
      Key DEL
      EndIf
      EndLoop
      Top
      Loop
      IfCharIs "»"
      ExitLoop
      EndIf
      Find RegExp "#MOFI_RULES#??????"
      Copy
      EndSelect
      Key LEFT ARROW
      Find MatchCase "^c"
      IfFound
      EndSelect
      Key HOME
      ">"
      Find MatchCase Up "^c"
      Replace ">^c"
      Key HOME
      Key DOWN ARROW
      Else
      DeleteLine
      EndIf
      EndLoop
      ClearClipboard
      Top
      Find RegExp "%#MOFI_RULES#*^p"
      Replace All ""
      Find RegExp "%>#MOFI_RULES#"
      Replace All ""
      Clipboard 0
      Find "»^p"
      Replace ""
      Top
      SortAsc 1 -1 0 0 0 0 0 0
      SaveAs ""

      Note: The macro switches to the UltraEdit style regular expression engine. If you prefer a different engine, add the command UnixReOn or PerlReOn at bottom of the macro.
      Best regards from an UC/UE/UES for Windows user from Austria

      26
      Basic UserBasic User
      26

        Aug 13, 2006#3

        Thanks!!! I'll try it out next week..... :D

        15
        Basic UserBasic User
        15

          Dec 20, 2007#4

          First, thanks Mofi for this macro. I was able to use it to solve a problem that I originally thought UC would do for me.

          As always, people like me want more. 8-)

          Where should I modify the macro so that, at the end, it marks which file each line left came from? I confess that I am a total newbie with UE macros. Any nudges you or others can give will be gratefully appreciated.

          6,668580
          Grand MasterGrand Master
          6,668580

            Dec 21, 2007#5

            Replace at the end of the macro the code lines

            Find "»^p"
            Replace ""
            Top
            SortAsc 1 -1 0 0 0 0 0 0
            SaveAs ""


            with following code lines:

            Find "»^p"
            EndSelect
            Key UP ARROW
            Key UP ARROW
            ColumnModeOn
            StartSelect
            Top
            "File 1: "
            EndSelect
            Find "»^p"
            Replace ""
            ColumnInsert "File 2: "
            ColumnModeOff
            Top
            SortAsc 1 -1 0 0 0 0 0 0
            SaveAs ""
            Best regards from an UC/UE/UES for Windows user from Austria