#!/bin/sh # @(#) Revision 1.4 - 06/24/96 # awkcol # # Count and summarize columns. # # usage: awkcol [-nopager] [file [...]] # # ============================================================================= # Sean Lee Hayden, Knoware Technology # shayden@knowaretech.com # # Bug reports, questions, and suggestions should be emailed to: # mobius@mobius-soft.com # # This software is provided under the terms of the GNU copyleft # (ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0), without a warranty # of any kind. Use at your own risk. # ============================================================================= # # configure me ################################################################ # # part 1 # # your awk needs to support the match function #AWK=awk #AWK=nawk AWK=gawk # part 2 # # set default pager pager="less -Me" # # part 3 # # set filter #filter="nodelspace" filter="cat" # configure me end ############################################################ if [ "$1" = "-nopager" ] then pager="cat" shift fi one=$1 two=$2 if [ ! "$one" -o ! "$two" ] then echo "usage: `basename $0` [-nopager] [file [...]]" echo "example: `basename $0` 19 6 10310_05.24" echo " column 19 for six positions is the date (e.g. 961205), " echo " so this lists all the different dates in 10310_05.24" echo "example: cat 10310_05.24 | `basename $0` 19 6" exit fi shift shift cat $* | $filter | $AWK '{ x[substr($0,STA,SIZ)]++ } END { for (i in x) { filler="" for (j = 1; j <= (SIZ - length(i)); j++) { filler = sprintf("%s ", filler) } spacematch = 0 for (k = 1; k <= length(i); k++) { pos = match("string1","[string2]") if (match(substr(i,k,1),/[ \t\n]/)) { spacematch++ } } if (spacematch == length(i)) { whitespace += x[i]; } else { printf ("%s%s %lu\n",i,filler,x[i]) } } if (whitespace) { for (j = 1; j <= SIZ; j++) { filler = sprintf("%s ", filler) } printf ("%s %lu\n",filler,whitespace) } }' STA=${one} SIZ=${two} | sort -n | $pager