2011-11-09 49 views

回答

1

排序的文件,你可以使用

$ join sortedfile1.txt sortedfile2.txt 

,你会得到的公共标识线连接起来。

2

工具comm可能是你想要的 - 给定来自两个文件的排序输入,它可以告诉你哪些行只在文件A中,哪些在两个文件中,哪些只在文件B中。例如,如果你有file-a是:

17 p o i u 
13 a b c d 
14 q w e r t 

...和file-b是:

18 a s d f 
13 f g h i 
7 z x c v 

您可以通过以下方式使用comm与进程替换:

$ comm -1 -2 <(cut -d ' ' -f 1 file-a|sort) <(cut -d ' ' -f 1 file-b|sort) 
13 

-1参数禁止仅在第一个文件中的行,并且-2禁止那些仅在第二个文件中的行。

0

cut -f1 file1 file2 | sort | uniq -d

相关问题