#!/usr/bin/perl -w use strict; use Getopt::Long; GetOptions( 'lines|n:i' => \my $lines, 'column|c:i' => \my $column, 'sep|s:s' => \my $separator, 'transform|f:s' => \my $transform, 'max|m' => \my $maximum_only, ); $lines ||= 10000; $column ||= 1; $separator ||= ";"; # should from the input, but... $column--; # adjust from human to Perl my %vals; my @F; my $line=0; sub transform{ $_[0] }; if ($transform) { no warnings 'redefine'; eval <) { @F = split /$separator/o; $vals{ transform($F[ $column ])}++; last FILE if $lines <= $line++; }; }; for (sort { $vals{$b} <=> $vals{$a} } keys %vals) { if ($maximum_only) { if ($vals{$_} / $lines > 0.6) { print "$_\n"; last } else { die "No confidence in '$_': Only $vals{$_} out of $lines values match\n"; }; } else { print "$_: $vals{$_}\n"; }; };