#!/bin/bash
#給emacs用,可計算中英文夾雜的文件字數,並忽略在org-mode裡的*#等符號
function start_count {
n1=`echo "$data_in_buffer" | sed \'s/[a-zA-Z][a-zA-Z]*//g\' | sed \'s/\\*//g\' \\
| sed -e \'s/[,。:;!?「」『』#,.:;?!《》]//g\' -e \'s/[()]//g\' -e \'s/[\\[\\]]//g\' -e \'s/[ \\t]//g\' \\
| awk \'BEGIN{n=0}{n+=length($0)}END{print n}\'`
n2=`echo "$data_in_buffer" | grep -o \'[a-zA-Z][a-zA-Z]*\' | wc -w`
total=`expr $total + $n1 + $n2`
}
total=0
while read data_in_buffer; do
start_count
done
echo "Total: ${total} words (not include puctuation)"