Skip to content

Instantly share code, notes, and snippets.

@bojieli
Created December 6, 2014 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bojieli/3965a7739fdf846c42e3 to your computer and use it in GitHub Desktop.
Save bojieli/3965a7739fdf846c42e3 to your computer and use it in GitHub Desktop.
Get per hour/date QQ message count and length in a two-people conversation
#!/bin/bash
# Usage: the first parameter should be the exported QQ message file
echo -e "Hour\tMyCnt\tMyLen\tMyAvglen\tHerCnt\tHerLen\tHer Avglen"; cat $1 | awk '/2014-/ { if($3=="boj") { split($2,time,":"); hour=time[1]; getline; me_len[hour]+=length($0); me_num[hour]++ } else { split($2,time,":"); hour=time[1]; getline; her_len[hour]+=length($0); her_num[hour]++ } } END {for(key in me_num) printf("%s\t%d\t%d\t%lf\t%d\t%d\t%lf\t\n", key, me_num[key], me_len[key], me_len[key] * 1.0 / me_num[key], her_num[key], her_len[key], her_len[key] * 1.0 / her_num[key] ) }' | sort -n
echo -e "Date\tMyCnt\tMyLen\tMyAvglen\tHerCnt\tHerLen\tHer Avglen"; cat $1 | awk '/2014-/ { if($3=="boj") { split($2,time,":"); hour=time[1]; getline; me_len[hour]+=length($0); me_num[hour]++ } else { split($2,time,":"); hour=time[1]; getline; her_len[hour]+=length($0); her_num[hour]++ } } END {for(key in me_num) printf("%s\t%d\t%d\t%lf\t%d\t%d\t%lf\t\n", key, me_num[key], me_len[key], me_len[key] * 1.0 / me_num[key], her_num[key], her_len[key], her_len[key] * 1.0 / her_num[key] ) }' | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment