From 19332446e2edfb34b998d5d14ff734c8f0660d1d Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 7 Oct 2015 17:33:20 -0400 Subject: bkt (bucketizer) initial commit --- bkt | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 bkt (limited to 'bkt') diff --git a/bkt b/bkt new file mode 100755 index 0000000..42ea6ea --- /dev/null +++ b/bkt @@ -0,0 +1,82 @@ +#!/usr/bin/perl -w + +use Getopt::Std; +$Getopt::Std::STANDARD_HELP_VERSION++; + +($SELF = $0) =~ s,.*/,,; +$VERSION="0.0.0"; + +sub HELP_MESSAGE { + print < ... + +Options are: + --help + -h display this help message + -c show counts only (suppress percentages) + -p show percentages only (suppress counts) + -w remove leading and trailing whitespace from input lines + -W remove ALL whitespace from input lines + -t show total count + -e code execute perl code for each line of input (should modify \$_, + make sure you quote the argument as needed by your shell) + +Input will be read from filenames given on the command line, or from +standard input if none given. The input need not be sorted. +EOF +} + +sub VERSION_MESSAGE { + print "$SELF $VERSION\n"; +} + +getopts('hcpwWte:', \%opt); + +HELP_MESSAGE() if $opt{h}; + +die "$SELF: can't give -c and -p options together\n" + if $opt{c} && $opt{p}; + +%counts = (); +$total = 0; + +while(<>) { + chomp; + if($opt{e}) { + eval $opt{e}; + die "$SELF: $@" if $@; + } + s/^\s+|\s+$//g if $opt{w}; + s/\s//g if $opt{W}; + $counts{$_}++; + $total++; +} + +for(sort keys %counts) { + print $_ . "\t"; + print $counts{$_} . "\t" unless $opt{p}; + printf "%.1f%%", ($counts{$_} * 100 / $total) unless $opt{c}; + print "\n"; +} + +if($opt{t}) { + print "\n-- Total count: $total\n"; +} + +exit(0); -- cgit v1.2.3