2016-12-01 4 views
-2

passend Ich habe zwei Dateien, die einige gemeinsame Spalten und einige sind nicht, und ich versuche Spalten mit gemeinsamen Spalten zugeordnet sind wie folgt hinzuzufügen:Werte von Spalten in zwei Dateien hinzufügen, wenn Zeilen nicht

Hinweis
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 

hier dass file2 enthält M260 dass file1 nicht, alles, was ich tun möchte, ist a) aufsummieren column2 von beiden Dateien, die gemeinsame column1 haben und die selten diejenigen lassen, wie sie sind, so dass

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' ist' 12862' und 'M272_0.6.motif_CBS_count 'ist' 4704' –

Antwort

1

Sie mit gawk versuchen können, , Feature PROCINFO das ist s pecific gaffen (Wenn Ausgabe Reihenfolge keine Rolle spielt dann diese Zeile entfernen)

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

Sie erhalten,

 
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 
Verwandte Themen