In Unix, is there any way to compare every text file in a directory to every other text file in the directory, and then sort each pair of files by similarity (using the diff
utility)? There are already some command-line Unix programs (such as fdupes) that can find duplicate files in a directory, but I'm wondering if it's possible to find similar files using a shell script as well.
-
It would probably be easier to compare one file to all other files in a directory. I'm still not sure how I'd sort the pairs of files by similarity, though.– Anderson GreenCommented Jan 8, 2013 at 7:58
-
Actually, I found a relevant search result just now. google.com/…– Anderson GreenCommented Jan 8, 2013 at 7:58
-
I found a program called binsort that might be able to do this, but I haven't tested it yet. neoscientists.org/~tmueller/binsort– Anderson GreenCommented Jan 8, 2013 at 8:00
-
Alternatively, I could simply obtain the Levenshtein distance for each pair of text files. Also, a list of string metrics can be found here: en.wikipedia.org/wiki/String_metrics– Anderson GreenCommented Jan 8, 2013 at 20:24
-
Here's a related question (about finding the longest common subsequence on Unix): stackoverflow.com/questions/9383067/…– Anderson GreenCommented Jan 8, 2013 at 20:36
|
Show 4 more comments
1 Answer
I think this question is too broad on so many levels. Term "difference" depends on type of data and its container: txt, mp3, avi, jpg. For each of them you need to execute their own processing methods. For instance, text or source code files may require only diff
utility. Music, video and image files require fuzzy logic and computer learning algorithms.
-
-
What I really want to do is group files by binary similarity - that's why I posted a link to binsort here. Commented Jan 8, 2013 at 17:42
-
Also, there is a program called
diff
which can be used to find the difference between two files. Also, I'm mainly concerned with text and source code files here. Commented Jan 8, 2013 at 17:43 -
Also, it would probably be easier to compare files of just one file type, instead of comparing files of all types. I think text files and source code files would probably be the easiest to compare. Commented Jan 8, 2013 at 17:51
-
I've narrowed down the question's scope to discuss only text files and source files, so the question is no longer too broad. Commented Jan 8, 2013 at 17:53