PS:呵呵,还有个问题,就是要显示出的列太多,屏幕实在是显示不下,所以就会造成显示跳行,如果是打印出来(也如上贴介绍过的,自行加入prin函数即可),那看上去应该没问题.或是把最后awk处理后的数据导出为文件,再用宽行显示器(VMORE)能正确显示.
#!/bin/ksh
#查询网点定活收支.利息支出..余额的脚本 V051128
#乐山市沙湾区邮政局 宋 涛
prin() #终端打印函数 #暂时未用
{
echo ""
cat $1 > $(tty)
echo ""
}
data()
{
month=$(date +%m)
day=$(date +%d)
year=$(date +%Y)
day=$(expr $day - 1)
if [ $day -eq 0 ]; then
month=$(expr $month - 1)
if [ $month -eq 0 ]; then
month=12
day=31
year=$(expr $year - 1)
else
month=$(printf "%02d" $month)
case $month in
01|03|05|07|08|10|12) day=31;;
04|06|09|11) day=30;;
02)
if [ $(expr $year % 4) -eq 0 ]; then
if [ $(expr $year % 400) -eq 0 ]; then
day=29
elif [ $(expr $year % 100) -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
esac
fi
fi
test $(expr length $day) -eq 1 && day=$(printf "%01d"$day)
day=${month}$day
}
input()
{
while :
do
clear
echo "\n\t\t\t收 支 量 查 询 表\n\n"
[ "$filedir" ] && echo "\n 请输入欲统计收支量的县级901机构号(回车默认为沙湾局): $filedir" \
|| read filedir?" 请输入欲统计收支量的县级901机构号(回车默认为沙湾局): "
[ "$filedir" ] || filedir="511111901"
case $filedir in
0) exit 0 ;;
511111901) dir="511111001 511111002 511111003 511111004 511111005 511111006" ;; #请在此更改或按此格式增加dir 变量
*) echo -n "\n 无此901机构号,请检查修改或增加脚本dir变量 \n" ; read ; filedir= ; continue ;;
esac
echo
[ "$day" ] && echo -n " 请输入欲统计收支量的日期(回车默认为昨日): ${day}" \
|| read day?" 请输入欲统计收支量的日期(回车默认为昨日): "
[ "$day" ] || { data ; break ; }
case $day in
0) exit 0 ;;
yesterday) data ; break ;;
esac
[ $(expr length $day) -ne 4 ] && { echo -n "\n 日期长度错误!\n" ; read ; day= ; continue ; }
[ "$(echo $day|egrep '^[0-1][0-9][0-3][0-9]$')" ] && break \
|| { echo -n "\n 日期输入错误!\n" ; read ; day= ; continue ; }
done
}
trap "tput sgr0 ; echo ; rm ~/yetj.dat 2>/dev/null; exit " 0 1 2 3 9 15
tput bold
scabs="scabs" #四川统版用户名
scabsdir=/usr/${scabs} #四川统版目录
filedir=$1 #县级901机构号
day=$2 #统计日期
[ "$LOGNAME" = "$scabs" ] || { echo "\n\n 请由 ${scabs} 用户执行本程序\n" ; exit 0 ; }
input
for name in $dir
do
filename=${scabsdir}/print/${name}/rpt_Mnacc_001${name}${day}.dat
[ -r $filename ] && tmpvar=$(tr "|" "\n" < $filename |sed -n '1p;2p;270p;273p;281p;284p;321p') || \
{ tmpvar=$(echo "$name" 暂无${day}日报表) ; echo $tmpvar >> ~/yetj.dat ; continue ; }
sumd=0;sumh=0
for lxname in ${scabsdir}/print/${name}/tlrbill*_001${name}${day}.dat
do
awk -F"|" '{if (NR==6) d=$8 ; if (NR==14) h=$8}
END {print d,h}' $lxname |read d h
sumd=$(echo $sumd+$d| bc 2>/dev/null)
sumh=$(echo $sumh+$h| bc 2>/dev/null)
done
echo $tmpvar $sumd $sumh >> ~/yetj.dat
done
clear
awk 'BEGIN{printf("\n%58s\n\n%-10s\n\n%-10s%-16s%-14s%-14s%-10s%-14s%-14s%-10s%-14s\n\n", \
"收 支 量 查 询 表","统计日期: '$day'","机构号","网点名","定期存入", \
"定期支出","利息支出","活期存入","活期支出","利息支出","余额")} \
{if (NF==2) {printf("%-10s%-16s\n",$1,$2)}
else {printf("%-10s%-16s%-14.2f%-14.2f%-10.2f%-14.2f%-14.2f%-10.2f%-14.2f\n",$1, \
substr($2,1,14),$3,$4,$8,$5,$6,$9,$7) ; sum3+=$3;sum4+=$4;sum5+=$5;sum6+=$6;sum7+=$7;sum8+=$8;sum9+=$9 } }
END{printf("\n%-26s%-14.2f%-14.2f%-10.2f%-14.2f%-14.2f%-10.2f%-14.2f\n","合计", \
sum3,sum4,sum8,sum5,sum6,sum9,sum7)}' ~/yetj.dat | pg