#!/afs/athena/contrib/perl5/perl

$str = shift(@ARGV);
while(<>){
	split;
	$ct++;
	if($ct%500 == 0){
	    print("processed $rct / $ct references\n");
	}
	next unless $_[6]=~/$str/;
#	next if $_[10] =~/$str/;
	push(@{$ref{$_[6]}}, $_[10]);
#	print("$_[10] -> $_[6]\n");
	$hits{$_[6]}++;
	$rct++;
}

foreach $dest (sort {$hits{$b} <=> $hits{$a}} keys %ref){
    print("$dest ($hits{$dest}) is pointed to by\n");
    %src = ();
    foreach $ref (@{$ref{$dest}}){
	$src{$ref}++;
    }
    foreach $s (sort {$src{$b} <=> $src{$a}} keys %src){
	print "\t$src{$s} $s\n";
    }
}
