I suggest that you create a hash to store the number of times you have seen something. Then, you can iterate over the hash to create the output.

Updated: So, I was a little behind on this and basically solved it the same way as other monks. Oops. That's what happens when your boss walks in while you are playing around on PM. :)

use strict; open (IN, "test.txt") or die "Can't open file: $!"; open (UNQ, "> unq.txt") or die "Can't open file: $!"; open (DUP, "> dup.txt") or die "Can't open file: $!"; my %hash; while (<IN>) { chomp; $hash{$_}++; } foreach (keys %hash) { if ( $hash{$_} > 1) { print DUP "$_\n"; } else { print UNQ "$_\n"; } } __END__ fraser:~$cat test.txt 0000 1111 2222 3333 4444 0000 3333 1111 5555 1111 0000 0000 1111 3333 6666 0000 fraser:~$cat unq.txt 6666 4444 2222 5555 fraser:~$cat dup.txt 0000 3333 1111 fraser:~$

</ajdelore>


In reply to Re: Separate duplicate and unique records by ajdelore
in thread Separate duplicate and unique records by wsee

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.