Sum total number of rows affected by queries

  Snippets, bash, bash snippets

Stupid command line tricks: I often run SQL jobs that can take many days to fully execute, and I always pipe the error and stdout to a file. As such, you end up with lots of lines like this in the output:Query OK, 81218 rows affected (52.76 sec)Here’s a silly one-liner that will quickly total up ALLLLLL the rows that have been affected. (this assumes the output is being directed to a file named do_archive.out)

grep affected do_archive.out | cut -d' ' -f3 | perl -nle '$sum += $_ } END { print $sum'

Want to format your number with commas?  Pipe it through this:

sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'