在两个文件中比较两列 [英] comparing two columns in two files

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

问题描述

我想两列在比较两个文件。

I would like to compare two columns in two files.

下面是一个例子:

1   722603  0.08    0.0013  0.0035  0.02
1   793227  0.17    0   0   0.01
2   931508  0.52    0.95    0.93    0.92

1   722603  0.0348543
1   793227  0.130642
2   931508  0.275751
2   1025859 0.0739543
2   1237036 0.476705

这code比较两个文件的第二列:

This code compares the second columns of the two files:

 awk 'FNR==NR {a[$2]++; next} a[$2]' file 1 file 2

然而,我要打印的共同的第二列,如果第一列也是相同的。更具体地,如果它在这两个文件发现722603,它必须检查的第一列也等于1,然后打印它。如果重复在第二列的数字,但重要的是它被打印一次以上以第1列的不同值

However, I want to print the common second column if the first column is also the same. More specifically, if it finds 722603 in both files, it must check that the first column is also equal to 1 and then prints it. If the number in second column is repeated, it is important that it gets printed more than once with different values of column 1.

我会很感激,如果你能引导我通过这个,谢谢你。

I'd be very thankful if you could guide me through this, thank you.

推荐答案

这样吗?扩展您的codeS了一下:

like this? extended your codes a bit:

awk 'FNR==NR {a[$1 FS $2]++; next} a[$1 FS $2]' file1 file2

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

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