简体   繁体   English

我可以使用join命令来连接两个在不同列上具有相似性的文件吗?

[英]Can I use join command to join two files that have similarities on different column?

I have two files. 我有两个文件。 one with three column (file 1): 一列三列(文件1):

AX-76297970 24 1000227
AX-76297974 24 1000999
AX-76297977 24 1001279
AX-76297978 24 1001552
AX-76297979 24 1001892
AX-76297985 24 1002443
AX-76297989 24 1002815
AX-76297993 24 1003894
AX-76297994 24 1004444

and another with several columns (file 2): 另一个有几列(文件2):

24      991     3       2       51.39   1       1       1       1       1       1       1       1       1       1       1       1       1       1       1       -5      1       1       1       1       1       1       1       1       1
24      1000227    4       1       35496.64        0       0       0.077   0       0       0.077   0       0       0       0       0.308   0       0       0       0       -5      0       0       0       0       0       0       0       0
24      1068    3       4       257.06  1       1       1       1       1       1       1       1       1       1       1       1       1       1       1       -5      1       1       1       1       1       1       1       1       1
24      1002443    4       2       66.67   1       1       1       1       1       1       1       1       1       1       1       1       1       1       1       -5      1       1       1       1       1       0.95    1       1       1
24      1094    3       4       98.21   1       1       1       1       1       1       1       1       1       1       1       1       1       1       1       0       1       1       1       1       1       1       1       1       1

what I want to do is to join these two files on column 3 of file 1 and column 2 of file 2.to get an output of all the columns of file 2 like this: 我想要做的是在文件1的第3列和文件2的第2列上加入这两个文件,以得到文件2的所有列的输出,如下所示:

24      1000227    4       1       35496.64        0       0       0.077   0       0       0.077   0       0       0       0       0.308   0       0       0       0       -5      0       0       0       0       0       0       0       0

24      1002443    4       2       66.67   1       1       1       1       1       1       1       1       1       1       1       1       1       1       1       -5      1       1       1       1       1       0.95    1       1       1

If you have the solution can you please explain it in detail so I can use it for different columns. 如果您有解决方案,请详细解释,以便在不同的专栏中使用。

thanks in advance 提前致谢

Something like 就像是

 join -1 3 -2 2 file1 file2

 -1 3 tells join to use column three (3) of the first file (-1)
 -2 2 tells join to use column two (2) of the second file (-2)

should do it. 应该这样做。 Maybe you will need to specify the separator: 也许您需要指定分隔符:

 join -t '\t' -1 3 -2 2 file1 file2

Have a look at the man page for the join command. 查看join命令的手册页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM