I can't really improve on FunkyMonk's solution, but it might be worthwhile to show how a data structure (hash-of-hashes-of-hashes, aka HoHoH) could be used. The following assumes that the data could include rows that are complete duplicates, and/or rows having the same key and the same "evalue", but different values in the middle columns.

The output will exclude duplicate data (that's what hashes are for); in the case of distinct rows having the same key and evalue, all rows will be included in the "combined" file, and the one with the (ascii-betically) lowest value in column two will be printed to the "lowest" file (you might want to modify that, by controlling how the sort is done in the innermost "for" loop).

#!/usr/bin/perl use strict; use warnings; my %data; while ( <DATA> ) { my ( $key, $fields, $evalue ) = ( /^(\S+)\s+(.*?\s(\S+))\s*$/ ); $data{$key}{$evalue}{$fields} = undef; } open my $f1, ">", "combined.data" or die $!; open my $f2, ">", "lowest.data" or die $!; for my $key ( sort keys %data ) { my $combined = ""; my $printed_lowest = 0; for my $evalue ( sort {$a<=>$b} keys %{$data{$key}} ) { for ( sort keys %{$data{$key}{$evalue}} ) { $combined .= "\t$_"; print $f2 "$key\t$_\n" unless ($printed_lowest++); } } print $f1 "$key$combined\n"; } __DATA__ Q3KIL4_PSEPF ONE 134 380 1 252 216.3 6.3e-64 Q3M236_ANAVT TWO 107 563 1 468 203.2 5.3e-60 Q3M236_ANAVT THREE 250 494 1 277 219.1 8.6e-65 Q3M5F5_ANAVT FOUR 296 608 1 355 166.2 7.4e-49 Q3M5F5_ANAVT FIVE 299 584 1 304 188.2 1.7e-55 Q3M7Z1_ANAVT SIX 51 181 1 140 99.0 1.2e-28 Q3MAD2_ANAVT SEVEN 107 508 1 468 350.1 3.3e-104 Q3MAD2_ANAVT EIGHT 230 457 1 277 201.1 2.3e-59 Q3MBT3_ANAVT NINE 203 606 1 468 102.5 1.1e-29 Q3MBT3_ANAVT TEN 326 559 1 277 221.6 1.6e-65 Q3MBT3_ANAVT ELEVEN 134 333 1 234 -334.1 2.7e-44 Q3MD63_ANAVT TWELVE 173 491 1 355 248.5 1.2e-73

In reply to Re: how to combine? by graff
in thread how to combine? by Anonymous Monk

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.