#!/.bi/bash
##			PAD

## stdin/stdout

if test $# -ne 0
then
	clear
	echo "
	
	USAGE:     pad < sparse_table
	
	A sparse table is a table with fields missing, which most
	PIRDE commands will choke on, so pad is provided to fill in
	the blanks. The PIRDE paste command uses pad and the unix
	paste command.	
	"
exit
fi



awk ' BEGIN { FS="	" }	  

NR == 2	{ fields = NF }
NR == 3	{ for (i = 1;i <= fields;i++)		## get sizes
		{ size[i] = length($i)
		}
	}
NR > 3  { extras = NF - fields 
	if ( extras != 0 )
		appendage = ""
		{ for (i = NF+1;i <= fields;i++)	## field pads loop
			{ fieldpad = "	"
		 	for (j = 1;j <= size[i];j++)
				{ fieldpad = fieldpad " "
				}
			appendage = appendage fieldpad 
			}
		}
	print $0 appendage
	}
'
#####################################################################
