As poj suggested, in these modern days importing into a relational database like Microsoft Access or sqlite might provide an easy SQL solution to your problem. If you want to look at your files as a text database then the problem looks like it fits an old text database processing tool: Awk. Perl has an awkish/autosplit '-a' mode suggesting:

#!/usr/bin/perl -a use strict; use warnings; our %recs; my $k = join "\t", @F[0 .. 3]; if ($recs{$k}) { $recs{$k}->{key_count}++; $recs{$k}->{rec}->[$_] += $F[$_] for 4, 5; } else { # careful to copy with [ @F ] not \@F here $recs{$k} = {key_count => 1, rec => [ @F ]}; } END { $recs{$_}->{rec}->[4] /= $recs{$_}->{key_count} foreach keys %recs +; print join("\t",@{$recs{$_}->{rec}}), $/ foreach sort { $recs{$a}->{rec}->[ 0 ] cmp $recs{$b}->{rec}->[ 0 ] || $recs{$a}->{rec}->[ 1 ] <=> $recs{$b}->{rec}->[ 1 ] || $recs{$a}->{rec}->[ 2 ] cmp $recs{$b}->{rec}->[ 2 ] || $recs{$a}->{rec}->[ 3 ] cmp $recs{$b}->{rec}->[ 3 ] } keys %recs; }
Ron

In reply to Re: Merging partially duplicate lines by mr_ron
in thread Merging partially duplicate lines by K_Edw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.