Looks like a challenge.  Here are some untested suggestions that might
might get you on the right track.  It does strike me odd that your
dot-qmail files look like that.  

On Fri, Jun 29, 2001 at 10:46:35AM -0500, Jay Kline wrote:
> * aliases where the name of the alias is contained in the first line of the
>   file (eg-  $i="john" in the script below, and the file's first line
>   is "johna")

[ -z `grep "^$i.*" /var/qmail/alias/.qmail-$i` ];

> * aliases where the first line of the file is contained in the filename
> 	(eg- $i="johnb" in the script below and the first line of the
> 	file is "john")

[ -z "`echo $i | grep $(head -1 /var/qmail/alias/.qmail-$)`" ];

> Does anyone have any ideas?

It might be easier to make a pass at the files and extract all this
data.  Then you can just process groups of three strings.  

Nate