Perl - Find duplicate lines in file or array
问题 I'm trying to print duplicate lines from the filehandle, not remove them or anything else I see asked on other questions. I don't have enough experience with perl to be able to quickly do this, so I'm asking here. What's the way to do this? 回答1: Using the standard Perl shorthands: my %seen; while ( <> ) { print if $seen{$_}++; } As a "one-liner": perl -ne 'print if $seen{$_}++' More data? This prints <file name>:<line number>:<line> : perl -ne 'print ( $ARGV eq "-" ? "" : "$ARGV:" ), "$.:$_"