1

我打算检查 .c 代码中提交的硬件答案。

有人有链接或 bash shell 脚本代码来检查文件相似性(相似行的百分比等)吗?

4

1 回答 1

2

Ready-to-use-programm
一方面,悉尼大学有一个名为Sherlock的小 C 程序,它完全可以满足您的需求:显示相似度百分比。你只需要自己编译它,但我认为这不会是一个问题。

自己做
另一方面,如果您使用的是基于 unix 的系统并想自己做这一切,可以使用以下comm命令:

compare two sorted files line by line and write to standard output: 
the lines that are common, plus the lines that are unique.
(taken from the manpage)

这里需要注意的重要一点是,它comm仅适用于已排序的文件,因此您必须先对它们进行排序。如果你有两个文件,比如说first.txtsecond.txt可以comm这样使用:

comm -12 <(sort first.txt) <(sort second.txt)

指定的 --12选项会抑制两个文件中唯一的行,因此您只会得到两个文件上出现的行。

于 2012-11-29T12:56:51.333 回答