#!/usr/bin/perl

my %servers;

$cachefile = $ARGV[0];
if ($ARGV[1]) {
	print "Usage: $ARGV[0] <cachefile>\n";
	exit;
}

print "Group: $groupname\n";

while (<>) {
	/^([^|]*)\|([^|]*)\|([^|]*)\|(.*)/;
	if (exists $servers{$3}) {
		push @{$servers{$3}}, "$1|$2|$4\n";
	} else {
		$servers{$3} = [];
		push @{$servers{$3}}, "$1|$2|$4\n";
	}
}

foreach (keys %servers) {
	print ":KEY: $_\n";
	open FH, ">$cachefile.$_" or die "Couldn't write new cachefile\n";
	foreach (@{$servers{$_}}) {
		print FH;
	}
	close FH;
}
