#!/usr/bin/perl use strict; use warnings; my ($fname, $dupcount) = @ARGV; die "USAGE: extract_duplicate_rows <# of duplicate rows>\n\n" unless $fname and $dupcount; open(my $IFILE, "<", $fname) or die "Cannot open $fname: $! "; my @buf; while (my $line = <$IFILE>) { if (@buf){ if (substr($line,0,10) eq substr($buf[0],0,10)){ push @buf,$line; next }; if (@buf ==$dupcount){ print @buf; }; }; @buf=($line); } @buf==$dupcount and print @buf; close $IFILE;