This is an easy job for perl. The general idea is:
my %seen; while (<>) { chomp; my @fields = split('\|', $_); if (my $record = $seen{$fields[0]}) { ... append @fields to $record... } else { $seen{$fields[0]} = ...some data structure... } } for my $k (keys %seen) { my $record = $seen{$k}; # process $record }
The reason for the ellipses is I'm not exactly sure what data you want to parse out, and after looking at your data more carefully, I realize that I should ask some questions about its structure.

Is each record one long line or is it 4 lines consisting of a | separated line, two alphabet lines and a blank line?

Also, do you know if your input is sorted? Even though perl can handle reading in 10K lines into memory, we can optimize the code if we know that the input is already sorted by id.

For the following I will assume that each record is 4 lines:

Then the above loop would look like:

my %seen; $/ = "\n\n"; while (<>) { chomp; my ($idline, @letters) = split(/\n/, $_); my @fields = split('\|', $_); my $record = $seen{$fields[0]}; unless ($record) { $seen{$fields[0]} = $record = { idline => $idline, letters => [ @letters ] }; } else { push(@{$record->{letters}}, @letters); } } for keys (%seen) { print join("\n", $seen->{$_}->{idline}, @{$seen->{$_}->{letters}}, " +\n"), "\n"; }

In reply to Re: How to eliminate redundancy in huge dataset (1,000 - 10,000) by pc88mxer
in thread How to eliminate redundancy in huge dataset (1,000 - 10,000) by Kenin

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.