2016-12-01 41 views
-2

我有有一些共同的列和几个不是两个文件,我试图添加与常见的列相关的列如下:这里从列在两个文件中添加值时,行不匹配

paste file1 file2 
M246_0.6.motif_CBS_count 15023 M246_0.6.motif_CBS_count 15767 
M247_0.6.motif_CBS_count 15023 M247_0.6.motif_CBS_count 15767 
M250_0.6.motif_CBS_count 8483 M250_0.6.motif_CBS_count 8815 
M254_0.6.motif_CBS_count 12921 M254_0.6.motif_CBS_count 13435 
M256_0.6.motif_CBS_count 36045 M256_0.6.motif_CBS_count 39390 
M261_0.6.motif_CBS_count 6339 M260_0.6.motif_CBS_count 2 
M262_0.6.motif_CBS_count 1026 M261_0.6.motif_CBS_count 6523 
M269_0.6.motif_CBS_count 47  M262_0.6.motif_CBS_count 863 
M271_0.6.motif_CBS_count 7162 M269_0.6.motif_CBS_count 57 
M272_0.6.motif_CBS_count 2245 M271_0.6.motif_CBS_count 8218 
M273_0.6.motif_CBS_count 159  M272_0.6.motif_CBS_count 2459 

注该文件2包含M260是文件1不,我想要做的是a)由具有共同COLUMN1两个文件加起来列2和离开罕见的人,因为他们是这样的

M246_0.6.motif_CBS_count 30790 
M247_0.6.motif_CBS_count 30790 
M250_0.6.motif_CBS_count 17298 
M254_0.6.motif_CBS_count 26356 
M256_0.6.motif_CBS_count 75435 
M260_0.6.motif_CBS_count 2 
M261_0.6.motif_CBS_count 72862 
M262_0.6.motif_CBS_count 1889  
M269_0.6.motif_CBS_count 104  
M271_0.6.motif_CBS_count 15380 
M272_0.6.motif_CBS_count 10463 
M272_0.6.motif_CBS_count 2459 
M273_0.6.motif_CBS_count 159  
+0

'M260_0.6.motif_CBS_count'是'12862'和'M272_0.6.motif_CBS_count '是'4704' –

回答

1

你可以尝试gawk ,功能PROCINFO是s pecific到呆子(如果输出顺序并不重要,然后删除此行)

awk '{d[$1]+=$2} 
    END{ 
     PROCINFO["sorted_in"] = "@ind_str_asc"; 
     for(k in d){ print k, d[k] } 
    }' file1 file2 

你,

 
M246_0.6.motif_CBS_count 30790 
M247_0.6.motif_CBS_count 30790 
M250_0.6.motif_CBS_count 17298 
M254_0.6.motif_CBS_count 26356 
M256_0.6.motif_CBS_count 75435 
M260_0.6.motif_CBS_count 2 
M261_0.6.motif_CBS_count 12862 
M262_0.6.motif_CBS_count 1889 
M269_0.6.motif_CBS_count 104 
M271_0.6.motif_CBS_count 15380 
M272_0.6.motif_CBS_count 4704 
M273_0.6.motif_CBS_count 159 
相关问题