#!/bin/sh
#
# Report failures by group ..
#

tmp=/var/tmp/bad
trap "rm -f $tmp.*; exit 0" 0 1 2 3 15

LC_COLLATE=POSIX

for f in *.out.bad
do
    [ "$f" = "*.out.bad" ] && break
    seq=`echo $f | sed -e 's/.out.bad$//'`
    grep "^$seq[ :]" group \
    | sed \
	-e 's/^[^ ]* //' \
    | tr ' ' '\012' \
    | sed \
	-e '/^local$/d' \
    | while read group
    do
	echo "$group $seq" >>$tmp.raw
    done
done

if [ -s $tmp.raw ]
then
    ( sort -t ' ' -k 1,1 -k 2,2n $tmp.raw ; echo "end-of-list" ) \
    | awk '
BEGIN		{ last_grp = "" }
$1 != last_grp	{ if (last_grp != "") print last_grp,nfail,tests
		  last_grp = $1
		  nfail = 1
		  tests = $2
		  next
		}
		{ nfail++
		  tests = tests " " $2
		}' \
    | sort -t ' ' -k 2,2nr -k 1,1d \
    | awk '{ $2 = ""; print }' \
    | while read grp tests
    do
	printf "%20.20s %s\n" "$grp" "$tests"
    done
fi
