#countdelims.pl #reports on the numbers of separators in lines of a text file #use strict; use Text::ParseWords; my ($new, $min, $max, $minline, $maxline, $syntax); $syntax=qq{\nSyntax: perl countdelims.pl separator filespec separator can be a character or string. Use \\t for tab. Use "|" for pipe or CMD.EXE will interpret it as a pipe command. Use , for CSV (with "..." delimiters). }; die "$syntax\n" unless $ARGV[1]; my $sep = qq($ARGV[0]); print "Separator: \"$sep\"\n"; shift; $max = 0; $min = 10e10; while (<>) { chomp; $new = quotewords( $sep, 0, $_) ; #print "$new\n"; if ($new < $min) { $min = $new; $minline = $.; } if ($new > $max) { $max = $new; $maxline = $.; } } print "Max: $max (e.g. line $maxline) Min: $min (e.g. line $minline)\n"; __END__ #First version, doesn't handle CSV: #countdelims.pl #reports on the numbers of delimiters in lines of a text file #but doesn't work in delimited-quoted files (e.g. CSV). $syntax=" Syntax: perl countdelims.pl delimiter filespec delimiter can be a character or string. Use \\t for tab. Use "|" for pipe or CMD.EXE will interpret it as a pipe command. "; die "$syntax\n" unless $ARGV[1]; $delim = qq($ARGV[0]); print "Delimiter \"$delim\"\n"; shift; $max = 0; $min = 10e10; while (<>) { chomp; $new = eval "tr/$delim/$delim/"; if ($new < $min) { $min = $new; $minline = $.; } if ($new > $max) { $max = $new; $maxline = $.; } } print "Max: $max (e.g. line $maxline) Min: $min (e.g. line $minline)\n";