#! /bin/sh
# Date:    Sat, 29 Dec 1990 17:31:41 -0500
# From:    cedman@golem.ps.uci.edu (Carl Edman)
# Subject: [comp.unix.shell] A one-liner to find files in archive servers
# Newsgroups: comp.archives
# A little one-line script to call up archie, get the list of all files specified
# by the exact match which is the first argument, sort these files by age
# and display them
ARCHIE=${ARCHIE-quiche.cs.mcgill.ca}
case $# in
0)	echo "Usage: $0 [-regex|-subcase|-sub] [-status] [-max maxhits] [-cmd archie_command] searchstring ..." >&2; exit 1;;
esac
(
 echo "unset status"
 echo "set maxhits 100"
 echo "set search exact"
 echo "set sortby none"
 while :
 do
	case "$1" in
	-exact)	echo "set search exact"; shift;;
	-regex) echo "set search regex"; shift;;
	-subcase) echo "set search subcase"; shift;;
	-sub) echo "set search sub"; shift;;
	-status) echo "set status"; shift;;
	-max)	echo "set maxhits $2"; shift; shift;;
	-cmd)	echo "$2"; shift; shift;;
	*)	break;;
	esac
 done
 for i
 do
	echo "prog $i" 
 done
) |
	rsh $ARCHIE -l archie "" |
	awk '/Host/ {
		host = $2;
	}
	/Last/ {
		cury = $6;
	}
	/Location:/ {
		dir = $2;
	}
	$0 ~ /FILE/ || $0 ~ /DIRECTORY/ {
		if (index($6, ":"))
			year = cury;
		else year = $6;
			printf "%3s %2s %4s %7s /%s:/%s/%s\n", \
				$4, $5, year, $3, host, dir, $7;
	}' 
# | sort +2nr -3 +0Mr -1 +1nr -2
