#!/bin/sh
# You may freely copy, modify and redistribution.
# This file for NeXTSTEP.
#	hironobu@sra.co.jp
#
#

echo $1 $2

awk 'BEGIN {	
	FS="|";
}
{
	 printf "cat %s %s | grep \"%s\" \n", F1, F2, $1;
}' F1=$1 F2=$2 $1 | sh | awk 'BEGIN	{ 
	FS="|" ;
	last_value=0;
	last_item="XX";
	sum=0.00; 
	n=0;
	printf("\n                     INDEX VALUES            \n");
	printf("TEST%40sBASELINE     RESULT      INDEX\n\n","");

}
{
	if ( last_item == $1 && last_item != "XX" ) {
		idex= $5 / last_value;
		sum += idex;
		++n;
		printf("%-40s  %10.1f %10.1f %10.1f\n",$1,last_value,$5,idex);
	}
	last_item = $1;
	last_value = $5;
}

END	{
	printf("              %30s                     =========\n","");
	printf("     SUM of %2d items  %30s  %20.1f\n",n,"",sum);
	printf("     AVERAGE          %30s  %20.1f\n","",sum/n);
}'

