這是一個簡單的財務賬單管理程序,個人原創(chuàng)。
主要包含如下功能如果需要有數(shù)據(jù),請確保程序目錄下包含data.csv
文件以及其相應數(shù)據(jù)。
data.csv
文件數(shù)據(jù)內(nèi)容如下:
2.增刪改查注意:使用第二種方法前請確保程序文件具有可執(zhí)行權限,可以使用
chmod +x finacialManager.sh
賦權。
添加
使用功能6賬單匯總觀察賬單添加效果
其他基本類似操作。
3.分類查詢根據(jù)數(shù)據(jù)里面的類型進行分類顯示
4.賬單匯總打印所有數(shù)據(jù)。
5.賬單排序6.賬單分析7.部分核心代碼sort_aod(){while [ true ]
do
tput clear
tput cup 2 10;echo "賬單排序模塊"
tput cup 4 10;echo "1.升序"
tput cup 5 10;echo "2.降序"
tput cup 6 10;echo "3.返回上級"
tput cup 8 0
read -p "請輸入選項>_" select
# read -p "升序或者降序?(y/n)" aod
case $select in
1) # 日期排序過程,sed去除表頭,sed替換-為,便于排序分隔, 對前3列進行排序使用-k -n表示以數(shù)值排序 ,最后合并日期添加-
echo "======================================================================="
awk 'BEGIN{printf "%10s %10s %6s %6s %6s %-6s\n","時間","金額","大分類","二級分類","支付方式","備注"}'
echo "-----------------------------------------------------------------------"
if (($1 == 1)) ; then
sed -n '2,$p' $DATA | sed -e "s/-/,/g" | sort -t "," -k 1,1n -k 2,2n -k 3,3n | awk -v FS=',' '{printf "%s-%s-%s %-10s %-6s %-6s %-6s %-6s\n",$1,$2,$3,$4,$5,$6,$7,$8}' | nl
elif (($1 == 2)) ; then
sed -n '2,$p' $DATA | sort -t "," -k $1,$1 -n | awk -v FS=',' '{printf "%-10s %-10s %-6s %-6s %-6s %-6s\n",$1,$2,$3,$4,$5,$6}' | nl
fi
echo "======================================================================="
;;
2)
echo "======================================================================="
awk 'BEGIN{printf "%10s %10s %6s %6s %6s %-6s\n","時間","金額","大分類","二級分類","支付方式","備注"}'
echo "-----------------------------------------------------------------------"
if (($1 == 1)) ; then
sed -n '2,$p' $DATA | sed -e "s/-/,/g" | sort -t "," -k 1,1nr -k 2,2nr -k 3,3nr | awk -v FS=',' '{printf "%s-%s-%s %-10s %-6s %-6s %-6s %-6s\n",$1,$2,$3,$4,$5,$6,$7,$8}' | nl
elif (($1 == 2)) ; then
sed -n '2,$p' $DATA | sort -t "," -k $1,$1 -r -n | awk -v FS=',' '{printf "%-10s %-10s %-6s %-6s %-6s %-6s\n",$1,$2,$3,$4,$5,$6}' | nl
fi
echo "======================================================================="
;;
3) sort_data
;;
*) error_chose_exception;sleep 1
;;
esac
read -p "輸入任意鍵繼續(xù)..." any
done
}
analyze_data(){ while [ true ]
do
tput clear
tput cup 2 10;echo "賬單分析模塊"
tput cup 4 10;echo "1.年度賬單分析"
tput cup 5 10;echo "2.月度賬單分析"
tput cup 6 10;echo "3.返回上級"
tput cup 8 0
read -p "請輸入選項>_" select
# read -p "升序或者降序?(y/n)" aod
case $select in
1)
tput cup 12 0
echo "**********年度賬單分析**********"
year=($(cat $DATA|sed -n '2,$p'|sed -e "s/-/,/g"|cut -d ',' -f 1|sort|uniq))
yearLen=${#year[*]} ; i=0
while (($i< $yearLen))
do
f_year="_year-$RANDOM$(date +%s%N | md5sum |cut -c 1-9)"
cat $DATA|sed -e "s/-/,/g"|awk -v FS=',' -v y=${year[$i]} '(NF!=0&&$1==y){printf "%s,%s,%s,%s,%s,%s,%s,%s,\n",$1,$2,$3,$4,$5,$6,$7,$8}' >$f_year
awk -v FS=',' -v y=${year[$i]} 'BEGIN{max=0;min=lshift(1,32)} {if ($4 >max) max = $4; fi}{if ($4< min) min = $4; fi} {sum += $4} END {printf "%s年總計%d條賬單,總計消費%.2f,年均消費%.2f元\n其中最高消費為%.2f元,最低消費為%.2f\n\n",y,NR,sum,sum/NR,max,min}' $f_year
rm $f_year
((i++))
done
echo "*******************************"
read -p "按任意鍵繼續(xù)..." any
;;
2)
read -p "輸入查詢的年份:" y
tput cup 12 0
f_year="_year-$RANDOM$(date +%s%N | md5sum |cut -c 1-9)"
cat $DATA|sed -e "s/-/,/g"|awk -v FS=',' -v y=$y '(NF!=0&&$1==y){printf "%s,%s,%s,%s,%s,%s,%s,%s,\n",$1,$2,$3,$4,$5,$6,$7,$8}' >$f_year
mon=($(cat $f_year|sed -e "s/-/,/g"|awk -v FS=',' -v y=$y '(NF!=0&&$1==y){printf "%s\n",$2}'|sort -n|uniq))
monlen=${#mon[*]} ; i=0
if (($monlen == 0))
then
echo "該年份下沒有數(shù)據(jù)!"
rm $f_year
read -p "按任意鍵繼續(xù)..." any
continue
fi
echo "**********${y}年月度賬單分析**********"
while (($i< $monlen))
do
f_mon="_mon-$RANDOM$(date +%s%N | md5sum |cut -c 1-9)"
awk -v FS=',' -v m=${mon[$i]} '(NF!=0&&$2==m){printf "%s,%s,%s,%s,%s,%s,%s,%s,\n",$1,$2,$3,$4,$5,$6,$7,$8}' $f_year >$f_mon
awk -v FS=',' -v m=${mon[$i]} 'BEGIN{max=0;min=lshift(1,32)} {if ($4 >max) max = $4; fi}{if ($4< min) min = $4; fi} {sum += $4} END {printf "%s月總計%d條賬單,總計消費%.2f,月均消費%.2f元\n其中最高消費為%.2f元,最低消費為%.2f\n\n",m,NR,sum,sum/NR,max,min}' $f_mon
rm -f $f_mon
((i++))
done
rm -f $f_year
echo "*******************************"
read -p "按任意鍵繼續(xù)..." any
;;
3) menu
;;
*) error_chose_exception;sleep 1
;;
esac
done
}
獲取完整資源壓縮包
聯(lián)系方式在程序里面
你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧