Line-by-line comparison (ignoring order) using Beyond Compare 3 or 4
Asked Answered
S

1

12

I am trying to perform a line-by-line comparison of contents in file using Beyond Compare 3 or 4. There is a caveat. The lines do not necessarily have the same order in the files. Examples below:

Example 1:

File 1 contents:
value1.key=mango
value2.key=pear

File 2 contents:
value2.key=pear
value1.key=mango

This should say "files identical" on comparison.

Example 2:

File 1 contents:
value1.key=mango
value2.key=pear
value3.key=apple

File 2 contents:
value2.key=pear
value3.key=banana
value1.key=mango

This should report only the following in the comparison:
value3.key=apple | value3.key=banana

Example 3:

File 1 contents:
value1.key=mango
value2.key=pear
value3.key=apple

File 2 contents:
value3.key=apple
value1.key=mango

This should report only the following in the comparison:
value2.key=pear

Can someone please tell me if this is achievable using Beyond Compare?

Shawn answered 16/12, 2014 at 15:17 Comment(2)
If you are allowed to sort both files first, this could definitely be done with diff, comm, and probably also with Beyond Compare (I'm not overly familiar with it, though). If you can't sort the files, something like awk, python or perl could be used to build a hash/map/dict of the lines in each file and then check that they are equivalent...Coldblooded
I have thought about that. I was wondering if there is anyway we can do without the sorting. There is also the {{sort}} command in dos available to sort file contents.Shawn
T
28

For those still interested:

When comparing files you can choose the files format (from the toolbar button "format"), just choose "sorted" and you can achieve this kind of comparison.

Theodoratheodore answered 14/5, 2015 at 7:33 Comment(1)
doesn't work for my case, but opening in Python I can load the files as lists of lines, and then create a set of lines out of the lists, and subtract the sets. I want BeyondCompare to load the lines as sets, which doesn't depend on sorting.Micro

© 2022 - 2024 — McMap. All rights reserved.