Is there a way in Unix, to evaluate how similar or dissimilar, two text files are?

I know about diff, but it just gives me the differences itself. What I am after is to just receive as an answer, some kind of evaluation of how much alike those two texts are. Do they contain much the same words, are the texts often quite similar etc. It is actually quite complicated to evaluate this in a high quality manner so I'm wondering if somebody has already done this.

Would be good to just receive a number, could then be that 0 means they are identical, and a high number means they are nothing alike.

closed as too broad by Satō Katsura, Jeff Schaller, techraf, Eric Renouf, GAD3R Nov 1 '16 at 11:55

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    There's an active research field related to this. Depending on what you want to do, answers can range from n-grams to sentiment analysis, to opinion mining, to automatic corpora classification. – Satō Katsura Nov 1 '16 at 9:55
  • Do you know of any open source solutions? Would be a shame if I spent work on something thats already been done and open sourced somewhere else. – Hermann Ingjaldsson Nov 1 '16 at 10:43
  • Your question is too broad to have an useful answer. – Satō Katsura Nov 1 '16 at 10:49
  • How could I narrow it down? – Hermann Ingjaldsson Nov 1 '16 at 10:53

There is diffstat which reads normal diff output and prints some stats more about lines only.

diff -u fileA fileB | diffstat

or wdiff to handle word diffs.

wdiff -123 --statistics fileA fileB

You may also read the man pages to find some more interesting options.

Not the answer you're looking for? Browse other questions tagged or ask your own question.