比较两个文件中的4列;(Compare 4 columns in two files; and output the line for unique combination (from first f

编程入门 行业动态 更新时间:2024-10-09 16:23:13
比较两个文件中的4列;(Compare 4 columns in two files; and output the line for unique combination (from first file) and line for duplicate combination (from second file))

我说有两个制表符分隔值文件

File1.txt chr1 894573 rs13303010 GG chr2 18674 rs10195681 **CC** chr3 104972 rs990284 AA <--- Unique Line chr4 111487 rs17802159 AA chr5 200868 rs4956994 **GG** chr5 303686 rs6896163 AA <--- Unique Line chrX 331033 rs4606239 TT chrY 2893277 i4000106 **GG** chrY 2897433 rs9786543 GG chrM 57 i3002191 **TT** File2.txt chr1 894573 rs13303010 GG chr2 18674 rs10195681 AT chr4 111487 rs17802159 AA chr5 200868 rs4956994 CC chrX 331033 rs4606239 TT chrY 2893277 i4000106 GA chrY 2897433 rs9786543 GG chrM 57 i3002191 TA

期望的输出:

Output.txt chr1 894573 rs13303010 GG chr2 18674 rs10195681 AT chr3 104972 rs990284 AA <--Unique Line from File1.txt chr4 111487 rs17802159 AA chr5 200868 rs4956994 CC chr5 303686 rs6896163 AA <--Unique Line from File1.txt chrX 331033 rs4606239 TT chrY 2893277 i4000106 GA chrY 2897433 rs9786543 GG chrM 57 i3002191 TA

File1.txt共有10个条目,而File2.txt有8个条目。 我想使用第1列和第2列比较文件。

如果文件的前两列值相同,则应将相应的行打印到File2.txt中的Output.txt。

当File1.txt具有唯一组合(Column1:column2,File2.txt中不存在)时,它应该将相应的行从File1.txt打印到Output.txt。

我在网站上尝试了各种awk和perl组合,但无法得到正确的答案。 任何建议都会有所帮助。

谢谢,阿米特

I have two tab separated values file, say

File1.txt chr1 894573 rs13303010 GG chr2 18674 rs10195681 **CC** chr3 104972 rs990284 AA <--- Unique Line chr4 111487 rs17802159 AA chr5 200868 rs4956994 **GG** chr5 303686 rs6896163 AA <--- Unique Line chrX 331033 rs4606239 TT chrY 2893277 i4000106 **GG** chrY 2897433 rs9786543 GG chrM 57 i3002191 **TT** File2.txt chr1 894573 rs13303010 GG chr2 18674 rs10195681 AT chr4 111487 rs17802159 AA chr5 200868 rs4956994 CC chrX 331033 rs4606239 TT chrY 2893277 i4000106 GA chrY 2897433 rs9786543 GG chrM 57 i3002191 TA

Desired Output:

Output.txt chr1 894573 rs13303010 GG chr2 18674 rs10195681 AT chr3 104972 rs990284 AA <--Unique Line from File1.txt chr4 111487 rs17802159 AA chr5 200868 rs4956994 CC chr5 303686 rs6896163 AA <--Unique Line from File1.txt chrX 331033 rs4606239 TT chrY 2893277 i4000106 GA chrY 2897433 rs9786543 GG chrM 57 i3002191 TA

File1.txt has total 10 entries while File2.txt has 8 entries. I want to compare the both the file using Column 1 and Column 2.

If both the file's first two column values are same, it should print the corresponding line to Output.txt from File2.txt.

When File1.txt has unique combination (Column1:column2, which is not present in File2.txt) it should print the corresponding line from File1.txt to the Output.txt.

I tried various awk and perl combination available at website, but couldn't get correct answer. Any suggestion will be helpful.

Thanks, Amit

最满意答案

下次,显示你的awk代码tryso我们可以帮助解决错误或丢失对象

awk 'NR==FNR || (NR>=FNR&&($1","$2 in k)){k[$1,$2]=$0}END{for(K in k)print k[K]}' file1 file2

next time, show your awk code tryso we can help on error or missing object

awk 'NR==FNR || (NR>=FNR&&($1","$2 in k)){k[$1,$2]=$0}END{for(K in k)print k[K]}' file1 file2

更多推荐

本文发布于:2023-07-17 10:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142767.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   文件   columns   files   output

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!