Linux Join - 命令未列出适当的输出

时间:2014-07-16 11:46:39

标签: linux unix rhel5

我有一个包含ID列表的文件,如

File1.csv

123456
1234234
2324324
325435345

和其他文件结构是这样的:

File2.csv

  1234234,asadasdas!w2eaesfd+smakdnjads,"points-ka"
  2131231,sadfasfa990-0;;'.sadsadsada,"points-ka"
  2324324,asadasdas!w2eaesfd+smasdasdfadewe,"points-ka"
  5434234234,adasdfsfhguse38873h78hu8i8377&*&*,"points-ka"

现在,我想使用此命令加入文件

加入-t,file1.csv file2.csv

但是这不是我输错的地方的任何输出吗?

必需输出:

 1234234,asadasdas!w2eaesfd+smakdnjads,"points-ka"
 2324324,asadasdas!w2eaesfd+smasdasdfadewe,"points-ka"

2 个答案:

答案 0 :(得分:1)

在加入之前,必须在连接键上对文件进行排序。

sort file1.csv > file1sorted.csv
sort file2.csv > file2sorted.csv
join -t, f1s.csv f2s.csv

1234234,asadasdas!w2eaesfd+smakdnjads,"points-ka"
2324324,asadasdas!w2eaesfd+smasdasdfadewe,"points-ka"

答案 1 :(得分:0)

连接的必要条件是文件应该先排序。

$ sort File1.csv > File1.sorted.csv

$ sort File2.csv > File2.sorted.csv

$ join -t, File1.sorted.csv File2.sorted.csv
1234234,asadasdas!w2eaesfd+smakdnjads,"points-ka"
2324324,asadasdas!w2eaesfd+smasdasdfadewe,"points-ka"