[net.sources] New version of cn

blm@cxsea.UUCP (Brian Matthews) (01/19/87)

A couple of months ago, a shell script called cn was posted. It used rn to
generate a multi-column list of unread news. It was nice, but I prefer
multi-column lists to be sorted vertically instead of horizontally, so I
added this capability to cn. I also check for a count of groups to display,
defaulting to 30, so you don't get 4 or 5 pages of output.

cn's usage is cn [ -v ] [ groups ]. If the -v is specified, the output will
be sorted vertically, otherwise it will be sorted horizontally. If a number
is included as an argument, this will be used as the maximum number of
groups to list. The default is 30.

I don't have the original article, so I don't know who originally posted cn.
There is an attribution in the script itself, which I've left.

Cut at the dotted line. The script does an exit, but you still might want to
remove my .signature.

------------------------- Cut Here -------------------------
#! /bin/sh
#
# cn - print available news in multi-column format.
#
# Adapted from a shell script originally written by:
# Sun Nov 30 22:34:48 EST 1986	(...!sunybcs!gworek / ...!boulder!forys)
# Modified:
# Mon Dec 15 08:30:05 PST 1986
# by
# Brian L. Matthews, ...uw-beaver!ssc-vax!cxsea!blm
#

GROUPS=30

while [ $# != 0 ]
do
    case $1 in
	-v)	vertical=1
		;;
	[0-9]*)	GROUPS=$1
		;;
	*)	echo usage: $0 [ -v ] [ groups ]
		exit 1
		;;
    esac
    shift
done

if [ -n "$vertical" ]
then
    rn -s$GROUPS -c | awk '
    /^etc.$/{
		etc = 1;
		exit;
	    }
	    {
		group[NR] = $4;
		count[NR] = $5;
	    }
    END	    {
		groups = NR - etc;
		rows = int ((groups + 2) / 3);
		for (i = 1; i <= rows; i++)
		{
		    for (j = i; j <= groups; j += rows)
			printf ("%3d %-21.21s ", count[j], group[j]);
		    print "";
		}
		if (etc)
		    print "etc...";
	    }'
else
    rn -s$GROUPS -c | awk '
    /^etc.$/{
		etc = 1;
		exit;
	    }
	    {
		printf ("%3d %-21.21s ", $5, $4);
		if (NR % 3 == 0)
		    print "";
	    }
    END	    {
		if (NR && NR % 3)
		    print "";
		if (etc)
		    print "etc...";
	    }'
fi

exit 0
-- 

Brian L. Matthews                               "Let's all work together
...{mnetor,uw-beaver!ssc-vax}!cxsea!blm          to help stop the spread
+1 206 251 6811                                  of country music."
Computer X Inc. - a division of Motorola New Enterprises