#!/usr/local/bin/perl # ~/bin/count_col.p c=1 # just counts how many non zeroes there are in col $c = 1 ; # How to override min and max values with command line eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $c -- ; $count = 0 ; while (<>) { if ($_ ne "\n" && !($_ =~ /^\#/ ) ) { s/^\s*//g ; # @fields = split(' ',$_); if ($c<0) { # count all cols foreach $f (@fields) { if($f ne "0") { $count ++ ; } } } else { if($fields[$c] ne "0") { $count ++ ; } } $rows ++ ; } } print "$count non zeroes in $rows rows\n" ;