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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |