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.
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....
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.