count-message.sh 727 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash -e
  2. # File: count-message.sh
  3. # Date: Wed Nov 29 02:32:40 2017 -0800
  4. # Author: Kangjing Huang <huangkangjing@gmail.com>
  5. if [[ -z $1 ]]
  6. then
  7. echo "Usage: $0 [Directory of text messages]"
  8. exit 1
  9. fi
  10. # TODO work on db directly
  11. echo -e "Filename\t#Lines\t#Chars\t#Words"
  12. SAVEIFS=$IFS
  13. IFS=$(echo -en "\n\b")
  14. for i in "$1"/*.txt
  15. do
  16. echo -en "$i\t"
  17. LINECOUNT=$(cat "$i"| wc -l )
  18. CHARCOUNT=$(cat "$i"| sed 's/.*:[0-9][0-9]:\(.*\)/\1/g' | sed 's/\[.*\]//g' | grep -v img | wc -m)
  19. WORDCOUNT=$(cat "$i"| sed 's/.*:[0-9][0-9]:\(.*\)/\1/g' | sed 's/\[.*\]//g' | grep -v img | wc -w)
  20. echo -e "$LINECOUNT\t$CHARCOUNT\t$WORDCOUNT"
  21. done | sort -t $'\t' -k 2 -n | column -t -s $'\t'
  22. IFS=$SAVEIFS