æ¥ä»ãæ¯åºé¡ãè²·ãç©ã®äžèº«ãã¿ãåºåãã§èšé²ãã.
幎ã¯æ¥ä»ã«å«ããã幎ããšã«ãã¡ã€ã«ãäœãããšã«ããŠã.
cat 2016.tsv
MM/DD\tYEN\tåè (è²·ã£ããã®ã®ã¡ã¢ãšã)
03/17\t108\tããŒãã
03/17\t380\tå€é£
ãã£ãšããéã䜿ããããããç¯çŽã§ããŠãããèŠç©ããããã®æ¹æ³ãšããŠã äžæ¥ãããã®æ¯åºãæããšã«åºããŠã¿ãŠãä»æã®é¡ãéå»ã®é¡ãšæ¯èŒãããšããã®ããã.
ä»æ¥äžæ¥ã®æ¯åºã ãšãã©ã€ãããã£ãŠåœåãªã®ã§ãäžã¶æã®ã¹ãã³ã§å¹³åãåºããã
以äžã®ã¹ã¯ãªããã perday
ãšããŠçœ®ã.
#!/bin/bash
TMP=`mktemp`
if [ $# == 0 ]; then
cat > $TMP
else
cp $1 $TMP
fi
echo "month average yen days"
for m in {01..12}; do
SUM=$(
cat $TMP | grep "^$m" | sort -k1,1 -n | grep ' ' | awk -v s=0 '{s+=$2} END{print s}'
)
DAYS=$(
cat $TMP | grep "^$m" | sort -k1,1 -n | grep ' ' | cut -f1 | uniq | wc -l
)
if [ $DAYS -gt 0 ]; then
echo -n "$m "
ruby -e "print sprintf('%12.3f %10d %5d', $SUM/$DAYS.to_f, $SUM, $DAYS)"
echo
fi
done
rm $TMP
./perday 2016.tsv
ãšã cat 2016.tsv | ./perday
ãšããŠäœ¿ã.
./perday 2015.tsv
month average yen days
06 1253.414 36349 29
07 1357.226 42074 31
08 1659.452 51443 31
09 1587.433 47623 30
10 1742.097 54005 31
11 2191.333 65740 30
12 2568.348 59072 23
./perday 2016.tsv
month average yen days
01 1474.258 45702 31
02 1870.379 54241 29
03 1482.125 23714 16