Given a set (2 or more) of tab-delimited .txt files in the format of:
File A:File B:I 9 A B 0.25 6 I 21 B A 1 6 I 33 C C 0.5 2 I 40 D D 1 2 I 56 A E 1 2
I 9 A B 0.30 8 I 21 B A 1 6 I 33 C C 1 2 I 40 D D 1 5
Is it possible to identify partially duplicate lines based solely on the contents of columns-1-4 and then merge the numerical contents of columns 5-6 into a single line? For example, given the two above .txt files, the desired output would be:
I 9 A B 0.275 14 I 21 B A 1 12 I 33 C C 0.75 4 I 40 D D 1 7 I 56 A E 1 2
i.e. if the contents of columns 1-4 match those of 1 or more other lines, average the numerical value in column 5 between all matched lines (for example on the first line - (0.25+0.3)/2 = 0.275) and sum the contents of column 6 between all matched lines (for example on the first line - 6+8=14). If the content of columns 1-4 is unique, print the line without modification (for example - the final line of File A which has no cognate partner within File B)
How could this be done? My knowledge of Perl is rather limited; I would presume I would need to read all of the lines into a single array and then perhaps use seen or the uniq function found in List::MoreUtils to begin to look for partial duplicate lines, but I am rather unsure. Thank you in advance for any help.In reply to Merging partially duplicate lines by K_Edw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |