本文介绍了比较两个未排序文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个制表符分隔的文件(请参阅下面的示例):

I have two tab separated files (please see the examples below):

Java    RAJ
PERL    ALEX
PYTHON  MAurice

(等)

ALEX    3.4
SAM     8.9
PEPPER  9.0

现在,举例来​​说如果说ALEX也在文件中找到2(它不是为确保ALEX会被发现)我应该有第三个文件看起来像这样:

Now, if for instance say ALEX is also found in file 2 (it is not for sure that ALEX will be found) I should have a third file looking like this:

PERL ALEX 3.4

在code应在文件1第2栏file2中检查所有的值。

The code should check for all the values in column 2 of file 1 in file2.

有关bash脚本有什么建议?

Any suggestions for a bash script?

推荐答案

您想要使用加入为。首先,你需要根据加盟,虽然现场进行排序:

You want to use join for that. First you need to sort according to join field though:

join -1 2 -2 1 <(sort +1 -2 file1) <(sort +0 -1 file2)

这篇关于比较两个未排序文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 15:21