alv*_*vas 12 unix diff file similarity
从unix终端,我们可以diff file1 file2
用来查找两个文件之间的区别.是否有类似的命令来显示2个文件的相似性?(必要时允许许多管道.
每个文件都包含一个带有字符串句子的行; 它们被排序并删除重复的行sort file1 | uniq
.
file1
:http://pastebin.com/taRcegVn
file2
:http://pastebin.com/2fXeMrHQ
输出应输出两个文件中出现的行.
output
:http://pastebin.com/FnjXFshs
我可以使用python这样做,但我认为放入终端有点太多了:
x = set([i.strip() for i in open('wn-rb.dic')])
y = set([i.strip() for i in open('wn-s.dic')])
z = x.intersection(y)
outfile = open('reverse-diff.out')
for i in z:
print>>outfile, i
Run Code Online (Sandbox Code Playgroud)
Nar*_*lei 29
如果你想获得重复行的列表而不诉诸AWK,你可以使用-d
flag来uniq:
sort file1 file2 | uniq -d
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
26202 次 |
最近记录: |