Ignore Lines and line Number when comparing two text files.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreedhar
    Visitor
    • Feb 2017
    • 3

    Ignore Lines and line Number when comparing two text files.

    Hi,

    I am currently using the latest version of the tool. I don't have experience with Regular Expression before. Here is what I am looking for.

    I have two files.
    File 1 contains text :
    TEXT|TEXT|TEXT||G|00100|TEXT|TEXT|TEXT|P|20151124| TEXT
    TEXT||TEXT TEXT TEXT ||||||||6548071000|||TEXT|TEXT|
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT|TD||||
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT||G|00100|TEXT|TEXT|TEXT|P|20151124| TEXT
    TEXT||TEXT TEXT TEXT ||||||||1234324569|||TEXT|TEXT|
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT|TD||||
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT||G|00100|TEXT|TEXT|TEXT|P|20151124| TEXT
    TEXT||TEXT TEXT TEXT ||||||||4528962220|||TEXT|TEXT|
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT|TD||||
    TEXT|TEXT|TEXT|TEXT|TEXT|||

    File 2 contains text:
    TEXT|TEXT|TEXT||G|00100|TEXT|TEXT|TEXT|P|20151124| TEXT
    TEXT||TEXT TEXT TEXT ||||||||1234324569|||TEXT|TEXT|
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT|TD||||
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT||G|00100|TEXT|TEXT|TEXT|P|20151124| TEXT
    TEXT||TEXT TEXT TEXT ||||||||6548071000|||TEXT|TEXT|
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT|TD||||
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT||G|00100|TEXT|TEXT|TEXT|P|20151124| TEXT
    TEXT||TEXT TEXT TEXT ||||||||5828962290|||TEXT|TEXT|
    TEXT|TEXT|TEXT|TEXT|TEXT|||
    TEXT|TEXT|TEXT|TD||||
    TEXT|TEXT|TEXT|TEXT|TEXT|||

    My requirement is like to compare only the 10-Digit number in the 2nd, 7th, 12th,... line and ignore all other lines( lines 1,3,4,5,6,8,9,10,11,13,14,15,...) . So if you look at the above two files and also in the attachment ( I highlighted the matching numbers in the attachment), the 10-Digit number that I am referring to is the same but it is in a different line number. So is there anyway in Beyond Compare that meets my requirement using regular expression or any rules in the tool.
    My file format is a regular text document. All the strings are delimited by '|'.

    Thanks in advance.
    Attached Files
  • Chris
    Team Scooter
    • Oct 2007
    • 5538

    #2
    Yes, you can do this in Beyond Compare 4.

    Open Beyond Compare.

    Open "Tools > File Formats".
    Click + to create a new format.
    Select "Text Format" as the type.
    Enter a mask that matches the extension of your files, such as *.txt.
    Go to the Grammar tab and click + in the top half of the tab.
    Name the element "10digits".
    Category: Basic
    Text matching: \d{10}
    Check regular expression.
    Save the format.
    If you want to give the format a specific name, right click on it in the format list and select Rename.

    Open your files in the Text Compare.
    If the file mask matches the format you defined, it should list "Format name" in the dropdown below the left and right path edit.
    Click the Rules toolbar button (referee icon).
    Uncheck "Everything else" and leave "10digits" checked.
    Click OK.

    If "View > Ignore Unimportant Differences" is turned on, then only differences in the 10 digit numbers will be shown.

    In the examples you listed, the text is also out of order. To ignore line ordering, you can make Beyond Compare sort your files before they are compared. To turn on sorting, open "Tools > File Formats". Select the format you just created. Go to the Conversion tab. Change the dropdown from None to Text Sort, then save the changes.

    After you turn on all of the above settings, Beyond Compare will sort your files before comparison, then it will only show differences in 10 digit numbers.
    Chris K Scooter Software

    Comment

    • sreedhar
      Visitor
      • Feb 2017
      • 3

      #3
      Hi Chris,

      Thank you very much for the input, I really appreciate it. By following the above mentioned steps I solved 50% of the requirement. But my complete requirement is like, line 27 (highlighted with yellow) in the below screenshot is exactly the same in both file 1 and file 2. But if you look at line 2 in file 1(left side) the 10 digit number 1234324569 matches with the 10 digit number in line 7 of the file 2 ( right side). Similarly 10 digit number in line 7 in file 1 matches with the 10 digit number in line 2 of file 2 in the right side. Even though they are in a different line number in both the files I want to see if they match. Your help is much appreciated.

      Thanks in advance.
      Attached Files

      Comment

      • sreedhar
        Visitor
        • Feb 2017
        • 3

        #4
        If the above response was not clear. Here is it simplified.

        Can we compare the 10-Digit number in File 1 to the same number in a Different row in File 2

        Comment

        • Chris
          Team Scooter
          • Oct 2007
          • 5538

          #5
          You need to turn on sorting in your file format as I described in my earlier post.

          In the examples you listed, the text is also out of order. To ignore line ordering, you can make Beyond Compare sort your files before they are compared. To turn on sorting, open "Tools > File Formats". Select the format you just created. Go to the Conversion tab. Change the dropdown from None to Text Sort, then save the changes.
          Chris K Scooter Software

          Comment

          Working...