#!/bin/sh
#	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.
#
# Copyright (C) 1993-2000 Paul A. Balyoz <pab@domtools.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

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 /usr/local/domtools/lib/ipsort.awk | $u

exit $?
