#! /bin/sh
#. Generate frequencies given a file, columns, and optional rec # and rec/case
case $# in
0) echo " ";
echo " usage: freq filename column(s) [r=record rc=records per case]" ;
echo " example: freq test.dat 8-13 r=2 rc=5" ;
echo " ";
exit 0;;
# *) echo " ";
# echo " error: ** syntax error/incorrect number of arguments **" ;
# echo " usage: freq filename column(s) [r=record rc=records per case]" ;
# echo " example: freq test.dat 8-13 r=2 rc=5" ;
# echo " ";
# exit 1;;
2) echo " ";
echo "freq of $1, column(s) $2";
echo " ";
echo " freq value";
echo " ";
cut -c$2 $1 | sort | uniq -c > /tmp/frtmp$$;
cat /tmp/frtmp$$;
awk 'BEGIN {print "-------------"}
{n += $1}
END { printf(" %d cases\n",n)}' /tmp/frtmp$$;
rm -f /tmp/frtmp$$;;
4) echo " ";
echo "freq of $1, column(s) $2, record $3, $4 records per case";
echo " ";
echo " freq value";
echo " ";
awk -f printrec0 $3 $4 $1 > /tmp/frtmp2$$;
cut -c$2 /tmp/frtmp2$$ | sort | uniq -c > /tmp/frtmp$$;
cat /tmp/frtmp$$;
awk 'BEGIN {print "-------------"}
{n += $1}
END { printf(" %d cases\n",n)}' /tmp/frtmp$$;
rm -f /tmp/frtmp$$;
rm -f /tmp/frtmp2$$;;
esac
echo " "
exit 0
(Note: credit for this shell script goes to Nelson Martinez).