Hi, I have a file (abc1.dat) with first field as table names and second field as previous months count and 3rd field as current months count. There are about 40 tables names in the file. This is the script I've written to find the percentage deviation for the two months.
Code:
cat ${workdir}/abc1.dat|awk '{
i = 0
if ( $2 > $3 )
{
diff = $2 - $3
i = 1
pd = ((($2 - $3) / $3) * 100)
}
else if ( $3 > $2 )
{
diff = $3 - $2
i = 1
pd = ((($3 - $2) / $2) * 100)
}
bteq << !!
.run file /db/d/lib/logon.script;
.SET SIDETITLES ON;
.SET TITLEDASHES OFF;
UPDATE AB_TABLE_${YYYY}
SET PD_ABC=$pd
WHERE MONTHLY_TABLE_NAME LIKE '$1';
.QUIT;
!!
errpct = $2 * 0.05
if ( (i == 1) && (diff > errpct) )
{ printf "%-30s %-30d %-30d\n", $1, $2, $3 }
}' >> ${logdir}/errortables.log