在unix中按一列合并两个文件 [英] Merging two files by a single column in unix

查看:22
本文介绍了在unix中按一列合并两个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 unix 中按一列合并两个文件.

I would like to merge two files by one column in unix.

我有文件_a:

subjectid name age  
12 Jane 16  
24 Kristen 90  
15 Clarke 78  
23 Joann 31  

我有另一个文件_b:

subjectid prob_disease  
12 0.009  
24 0.738  
15 0.392  
23 1.2E-5  

我想在命令行中合并这些文件.我想通过subjectid合并文件a和b.由于每个文件大约有 200 万行长,我在 R 中尝试过,但由于数据量很大,它冻结了,有人可以帮我在 linux 中做到这一点吗?期望输出:

I would like to merge these files in the command line. I'd like to merge files a and b by subjectid. Since each file is about 2 million lines long, I tried in R but it froze due to the amount of data, could someone please help me do this in linux? Desired output:

subjectid prob_disease name age  
12 0.009 Jane 16  
24 0.738 Kristen 90   
15 0.392 Clarke 78  
23 1.2E-5 Joanna 31     

请帮忙,谢谢!

推荐答案

查看 join(1).就您而言,您甚至不需要任何标志:

Check out join(1). In your case, you don't even need any flags:

$ join file_b file_a
subjectid prob_disease name age
12 0.009 Jane 16
24 0.738 Kristen 90
15 0.392 Clarke 78
23 1.2E-5 Joann 31

这篇关于在unix中按一列合并两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆