count-message.sh 711 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash -e
  2. # File: count-message.sh
  3. # Date: Sun Apr 12 21:01:01 2015 +0900
  4. # Author: Kangjing Huang <[email protected]>
  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\tCounts of message\tCounts of chars\tCounts of 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
  22. IFS=$SAVEIFS