简体   繁体   English

基于Linux中的公共列合并两个不同长度的文件

[英]merge two files of different length based on common column in linux

I would like to merge two files (file 1 & file 2) based on a common column to give (file 3). 我想基于一个公共列合并两个文件(文件1和文件2)以给出(文件3)。 File 3 should have only the matched ids (mid) leaving out the mid=20 THE COMMON COLUMN HERE WOULD BE 'MID' AND THE MATCH IS BASED ON THAT COLUMN 文件3应该仅具有匹配的ID(mid),而忽略mid = 20。在这里,普通列将是“ Mid”,并且匹配基于该列

I can do it with J command but the file 1 and file 2 are of different lenghts. 我可以用J命令来做,但是文件1和文件2的长度不同。 Please suggest some ideas. 请提出一些想法。 Thanks in advance. 提前致谢。

file 1 文件1

mid A1  A2  A3  A4  A5  A6
18  we  gf  32  23  45  89
19  ew  fg  33  24  46  90
21  ew  fg  35  26  48  92

file 2 文件2

mid B1  B2  B3  B4
18  r40 1   103 NA
19  r41 1   104 NA
20  r42 1   105 NA
21  r43 1   106 NA

file 3 文件3

mid B1  B2  B3  B4  A1  A2  A3  A4  A5  A6
18  r40 1   103 NA  we  gf  32  23  45  89
19  r41 1   104 NA  ew  fg  33  24  46  90
21  r43 1   106 NA  ew  fg  35  26  48  92

join正是针对此类任务而设计的:

join file2 file1

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

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