#!/usr/bin/perl # Assuming that you have perl, and that you have changed the permissions on this file so that it can be executable ("chmod u+x get_nrc") # then the usage is: # get_nrc [filename] # # written by: Jaideep Singh # date: February 01, 2007 # email: singhj AT jlab DOT org # # description: gets the number of rows and columns of a tab separated file # $filename = $ARGV[0]; open(FILE,"<$filename") or die "File could not be opened: $filename\n"; $delimiter = "\t"; $row_count = 0; $column_count = 0; $max_column = 0; $min_column = 0; while () { chomp; @columns = split /$delimiter/; $column_count += $#columns+1; if ($row_count == 0) { $max_column = $#columns + 1; $min_column = $#columns + 1; } else { if ($#columns + 1 > $max_column) { $max_column = $#columns + 1; } if ($#columns + 1 < $min_column) { $min_column = $#columns + 1; } } $row_count++; } close(FILE); if ($row_count > 0) { $column_count = $column_count/$row_count; print "total number of Rows: $row_count\n"; print "average number of Columns: $column_count\n"; print "minimum number of Columns: $min_column\n"; print "maximum number of Columns: $max_column\n"; } else { print "No rows\n"; }