Let's say I have two files and you want to know how many equal lines they have. For example, file1 is
1 3 2 4 5 0 10
and file2 contains
3 10 5 64 15
In this case, the answer should be 3 (common lines: "3", "10" and "5").
This, of course, was done quite simply with python, for example, but I was curious to do it from bash (with some standard utilities or additional things like awk or something else). Here is what I came up with:
cat file1 file2 | sort | uniq -c | awk '{if ($1 > 1) {$1=""; print $0}}' | wc -l
This seems too complicated for the task, so I wonder if there is an easier or more elegant way to achieve the same result.
PS The output of the percentage of the total part of the number of lines in each file will also be pleasant, although this is not necessary.
UPD: Files do not have duplicate lines
source share