卒論の文字数をカウント

卒論シーズンなので
texファイルの文字数を数えるワンライナー
一応頭に\と%の行はカウントしない。

ruby -e 'just=ARGV.map{|a|a.size}.max;total=0;ARGV.each{|arg|words=0;open(arg){|f|f.each{|line|words+=line.chomp.strip.split(//u).size unless line=~/ *[\\%]/}};puts "#{arg.ljust(just)}:#{words}";total+=words}; puts "total".ljust(just)+":#{total}"' *.tex

最後に*.texを渡すとディレクトリ内のtexファイル全部計算してtotalも計算する