Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find duplicate line 1

Status
Not open for further replies.

rozzay

Programmer
Jan 3, 2002
142
US
Hi I have a file that have thousands of lines I would like to create a perl script that looks at each and scan through to see if any of lines are duplicates. Any help or link is appreciated.
 
Code:
my %duplicates = ();
open (FH,'file.txt') or die "$!";
while (my $line = <FH>) {
   chomp($line);
   $duplicates{$line}++;
   if ($duplicates{$line} > 1) {
      print "This is a duplicate line: $line\n";
   }
}

The above will only tell you if the line is duplicated. I predict you will ask another question.... ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top