#!/usr/bin/perl use strict; # Usage: uniquecol [column-number] +[count] # Only output unique rows in column x my $col = 0; my $cnt = 0; my $status = 0; while( $_ = pop(@ARGV) ) { /^\d+$/ && ($col = $_); /^\+(\d+)$/ && ($cnt = $1); /^-s$/ && ($status = 1); } my %records; my %count; if( $cnt ) { # Read in the papers that have $cnt changes while( ) { if( $status ) { my $l = length($status); while($l--) { print STDERR "\b"; } print STDERR $status++; } split; ($records{@_[$col]} = $_) unless (exists $records{@_[$col]}); $count{@_[$col]}++; } # Write out the papers that have $cnt changes my $ref; if( $status ) { print STDERR "\nOutputting results: "; $status = 1; print $status; } foreach $ref (sort {$a <=> $b} keys %records) { next if ($count{$ref} != $cnt); print $records{$ref}; if( $status ) { my $l = length($status); while($l--) { print STDERR "\b"; } print STDERR $status++; } } } else { while( ) { split; next if $records{@_[$col]}; $records{@_[$col]} = 1; print; } }