#!BOURNESHELL
#	program:	ipsort
#	purpose:	Filter that sorts data lines by IP address, leftmost octet
#			first, second octet next, and so on.  The "-u" option
#			removes excess duplicate lines (like "uniq").
#	input:		Lines of data with IP addresses as first field on stdin.
#			Fields are separated by whitespace (space, tab).
#			All fields other than the first are copied through without
#			any processing.
#	output:		Sorted input lines or the word "ERROR" (distinguishable
#			from a real record because it has no period in it).
#	exit value:	0 if succeeds, 1 if fails (and "ERROR" output),
#			or exit value of last filter used.
#

usage() {
	echo "usage: $0 [-u]" >&2
	exit 1
}

if test $# -gt 1; then
	usage
fi

u='cat'
for arg do
	case $arg in
		-u)	u='uniq' ;;
		*)	usage ;;
	esac
done

awk -f DOMLIB/ipsort.awk | $u

exit $?
