#!/bin/sh

PATH=/bin:/usr/bin
GRPCHARS=",-a-z0-9."

case $# in
0|1|2|3|4|5|6|7) # For only a few arguments, it's wasteful to have big pipelines.
	for i
	do
		2> /dev/null sed -n "/^Newsgroups: [$GRPCHARS]*$/s/,/ /g
			   /^Newsgroups: \([ $GRPCHARS]*\)$/s//\1/p
			   10q" $i
	done ;;
*)	# For lots of arguments, the for loop is wasteful.
	2> /dev/null grep '^Newsgroups: ' $* |
		sed "s/\([0-9]*\):Newsgroups: \(.*\)/\2 \1/" |
		uniq -1  | sed "s/ [0-9]*$//
			s/,/ /g"
esac
