If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Getting Beyond Compare to Match Similar Lines as Desired

17-Feb-2017, 05:56 AM

I am using Beyond Compare 4.1.6 to diff text configuration files. There is one configuration parameter per line, and each line is formatted as follows: :=

I would like to configure Beyond Compare such that it will align only lines when the : portion of the line is exactly the same in both files. Put differently, everything from the beginning of the line up to and including the colon must match exactly for the two lines to be aligned. Note that a colon cannot occur in , so the colon I want Beyond Compare to base its alignment decision on will always be the first colon in the line.

An example is:

# FILE 1
abcdefgh:string=5

# FILE 2
abcdefkh:string=5

Beyond Compare aligns these two lines even though I don't want it to.

I've been unable to coerce Beyond Compare to compare lines as desired by editing its grammar rules or by tweaking other features.

In the Text Compare, you can define a grammar which matches on that specific Regular Expression. For the beginning of the line to the first colon, you could use:
^[^:]+:

This is defined in the File Format. Create a new format in the Tools menu -> File Formats dialog; New + Text Format. In the grammar tab, define this Basic Reg Expression and give it a custom name.
If your files have a unique extension, binding the format to that extension type in the first tab is useful, too.

In the Text Compare, you can then go to the Session menu -> Session Settings, and mark that new element as Important (checked) and "Everything Else" as Unimportant. In the Alignment tab, set to Never Align Differences.

Now your files will only align if the important (custom grammar element) text is equal, and everything else is unimportant. Unimportant differences are still differences as long as they are blue. If you enable the Ignore Unimportant Differences toggle, then they'll be ignored and set to black text. So if you need to compare them, be careful that this toggle remains disabled.