Skip to content

Instantly share code, notes, and snippets.

@jiapengjun
Created August 19, 2022 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiapengjun/95ce0fe1ea8c6a27fd07d94c3076e022 to your computer and use it in GitHub Desktop.
Save jiapengjun/95ce0fe1ea8c6a27fd07d94c3076e022 to your computer and use it in GitHub Desktop.
#!/bin/bash
m_cnt=0
m_vln=0.0
t2_cnt=0
t2_vln=0.0
w_cnt=0
w_vln=0.0
t4_cnt=0
t4_vln=0.0
f_cnt=0
f_vln=0.0
while read date earning
do
weekday=$(date -j -f '%Y-%m-%d' ${date} +'%A')
case $weekday in
Monday)
m_cnt=$((m_cnt+1))
m_vln=$(echo ${earning%\%} + $m_vln | bc)
;;
Tuesday)
t2_cnt=$((t2_cnt+1))
t2_vln=$(echo ${earning%\%} + $t2_vln | bc)
;;
Wednesday)
w_cnt=$((w_cnt+1))
w_vln=$(echo ${earning%\%} + $w_vln | bc)
;;
Thursday)
t4_cnt=$((t4_cnt+1))
t4_vln=$(echo ${earning%\%} + $t4_vln | bc)
;;
Friday)
f_cnt=$((f_cnt+1))
f_vln=$(echo ${earning%\%} + $f_vln | bc)
;;
*)
echo $weekday $earning
;;
esac
done < <(cut -f 1,4 160213)
m_avg=$(echo "scale=2; $m_vln/$m_cnt" | bc)
echo "Mon: " $m_cnt $m_vln $m_avg
t2_avg=$(echo "scale=2; $t2_vln/$t2_cnt" | bc)
echo "Tue: " $t2_cnt $t2_vln $t2_avg
w_avg=$(echo "scale=2; $w_vln/$w_cnt" | bc)
echo "Wed: " $w_cnt $w_vln $w_avg
t4_avg=$(echo "scale=2; $t4_vln/$t4_cnt" | bc)
echo "Thu: " $t4_cnt $t4_vln $t4_avg
f_avg=$(echo "scale=2; $f_vln/$f_cnt" | bc)
echo "Fri: " $f_cnt $f_vln $f_avg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment