|
|
Question : Fetching the duplicates
|
|
INPUT: --------------------------------------------- JACK|......||||||||||...... AMBROSE|.........||||| JOHN|.........||||| TOM|.........||||| JACK|.........||||| TOM|.........||||| STEVE|.........||||| JACK|.........||||| JOHN|.........||||| TOM|.........||||| CRIS|.........||||| TOM|.........||||| STEVE|.........|||||
hi all,
Nice to join in Perl group.
Basically I am good in sql script, I started learning perl. I am trying hard to write a script in perl for pulling duplicates. Could anyone help me to do it?
In the above given examples, I have to sort the data as per the first column (namely JACK, AMBROSE,....) After sorting I have to pull out only the records which are found twice or more than twice as per the below output format.
Also I like to check the count of unique records. For this example, we have 4 unique records (ex., JACK, JOHN, STEVE, TOM)
I tried with the following script, but I couldn't complete it, Could anyone help me? Thanks in advance.
Jackson.
OUTPUT: ---------------------------------------
JACK|......||||||||||...... JACK|.........||||| JACK|.........||||| JOHN|.........||||| JOHN|.........||||| STEVE|.........||||| STEVE|.........||||| TOM|.........||||| TOM|.........||||| TOM|.........||||| TOM|.........|||||
open (FILE,"D:/perl/bin/grouping/input1.txt");
open (OUT, ">D:/perl/bin/grouping/output.txt");
my %keys; while () { my ($first, @data) = split(/\t/,$_);
#print @data; #print "hai\n";
push @{$keys{$first}}, @data; }
foreach (sort keys %keys) { print join ' ', $_, sort @{$keys{$_}}; print "\n"; }
|
Answer : Fetching the duplicates
|
|
also...i keep thinking about what stefan73 said...maybe you need to declare the loop variable outside the while loop also, ie...
my $line; while ($line = ) {
instead of...
while (my $line = ) {
|
|
|
|
|