如何将文件 1 的列与另一个文件 2 的文本相匹配,然后匹配打印文件 2

如何将文件 1 的列与另一个文件 2 的文本相匹配,然后匹配打印文件 2

文件1

Name,TaxID,Lineage,Count,Proportion_All(%),Proportion_Classified(%)
Acaryochloris marina,155978,Bacteria;Cyanobacteria;;Synechococcales;Acaryochloridaceae;Acaryochloris,4,0.000218669,0.00120249
Anabaena cylindrica,1165,Bacteria;Cyanobacteria;;Nostocales;Nostocaceae;Anabaena,9,0.000492005,0.00270561

文件2

Object_ID, Length, Assignment
NODE_1_length_501653_cov_19.284,501653,1727163
NODE_2_length_458856_cov_17.1812,458856,374606
NODE_3_length_369230_cov_19.3769,369230,1727163
NODE_4_length_342860_cov_16.7318,342860,83263
NODE_5_length_301494_cov_19.1256,301494,1727163
NODE_6498_length_5833_cov_14.8079,5833,155978
NODE_6499_length_5833_cov_4.85133,5833,NA
NODE_6500_length_5831_cov_23.1697,5831,553814
NODE_6501_length_5831_cov_22.403,5831,795665

输出

Object_ID, Length, Assignment
NODE_6498_length_5833_cov_14.8079,5833,155978

文件 1 第二列中的 ALl 值与文件 2 最后一个数组中的文本匹配,如果找到,则打印文件 2。

答案1

使用awk:

awk -F, 'NR==FNR {TaxID[$2]=1; next} FNR==1 || $NF in TaxID' File1 File2
Object_ID, Length, Assignment
NODE_6498_length_5833_cov_14.8079,5833,155978

相关内容