This does the job:

my %data; while (<DATA>) { chomp; my ($firstnum, $secondnum, $thingy, @bits) = split /\s/; my $key = sprintf("%s\x00%s\x00%s", $firstnum, $secondnum, $thingy +); for my $i (0 .. $#bits) { $data{$key}[$i] = [] unless exists $data{$key}[$i]; push @{ $data{$key}[$i] }, $bits[$i]; } } foreach my $key (sort keys %data) { print join q[ ], split "\x00", $key; print q[ ]; print join q[ ], map { join '/', @$_ } @{ $data{$key} }; print "\n"; } __DATA__ 1 51 Brahui A C A A T 1 51 Brahui A C A G T 3 51 Brahui A C A G C 3 51 Brahui A C G A T 5 51 Brahui A C G A T 5 51 Brahui A C G G C 7 51 Brahui A C G A T 7 51 Brahui A C G G T 9 51 Brahui A C G G T 9 51 Brahui A C G G T

But don't just copy that as-is. Try to understand how it works. What you want to look at is:

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

In reply to Re: How to match duplicate lines in a text file and extract only one of those lines to a new file by tobyink
in thread How to match duplicate lines in a text file and extract only one of those lines to a new file by danica

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.