eg1:AWK匹配列汇总:
[quote]
-- (1)
[zhuxu@dbadb1 tmp]$ cat temp.log | grep "Query OK" |head
Query OK, 21401 rows affected (10.00 sec)
Query OK, 15560 rows affected (1.40 sec)
Query OK, 23588 rows affected (14.07 sec)
Query OK, 15249 rows affected (1.80 sec)
Query OK, 22519 rows affected (13.02 sec)
Query OK, 15535 rows affected (1.51 sec)
Query OK, 23665 rows affected (12.40 sec)
Query OK, 15676 rows affected (1.57 sec)
Query OK, 24608 rows affected (12.65 sec)
Query OK, 15159 rows affected (1.85 sec)
-- (2)
[zhuxu@dbadb1 tmp]$ cat temp.log | grep "Query OK" | awk -F"[ (]" 'BEGIN{rows=0;times=0} {rows+=$3;times+=$7} END{print "\nTotal rows: "rows,"\nTotal Times(min): "times/60"\n"}'
Total rows: 9990253
Total Times(min): 76.8903
[zhuxu@dbadb1 tmp]$
[/quote]
eg2:AWK列分组GRUP BY汇总SUM:
[quote]
$head zx.log
2011-01-19 10
2011-01-19 10
2011-01-19 100
2011-01-19 1042
2011-01-19 10422
2011-01-19 1059
2011-01-19 1059
2011-01-19 10887
2011-01-19 1140
2011-01-19 11724
$awk '{name[$1]+=$2;sum+=$2} END {for(i in name) print i,name[i];print "=====> Total:",sum,"<=====";}' zx.log | sort -k1 -M
2011-01-19 496582
2011-01-20 1039690
2011-01-21 364867
2011-01-22 1200747
2011-01-23 112981
2011-01-24 465766
2011-01-25 1081170
2011-01-26 1111863
2011-01-27 335430
2011-01-28 450190
2011-01-29 120003
2011-01-30 99402
2011-01-31 262238
2011-02-01 240861
2011-02-02 181618
2011-02-03 145767
2011-02-04 133216
2011-02-05 100355
2011-02-06 99856
2011-02-07 138638
2011-02-08 142822
2011-02-09 511951
2011-02-10 496962
2011-02-11 669015
2011-02-12 1750215
2011-02-13 629162
=====> Total: 12381367 <=====
[/quote]
http://chenxu.yo2.cn/articles/shell_awk_if.html
[quote]
-- (1)
[zhuxu@dbadb1 tmp]$ cat temp.log | grep "Query OK" |head
Query OK, 21401 rows affected (10.00 sec)
Query OK, 15560 rows affected (1.40 sec)
Query OK, 23588 rows affected (14.07 sec)
Query OK, 15249 rows affected (1.80 sec)
Query OK, 22519 rows affected (13.02 sec)
Query OK, 15535 rows affected (1.51 sec)
Query OK, 23665 rows affected (12.40 sec)
Query OK, 15676 rows affected (1.57 sec)
Query OK, 24608 rows affected (12.65 sec)
Query OK, 15159 rows affected (1.85 sec)
-- (2)
[zhuxu@dbadb1 tmp]$ cat temp.log | grep "Query OK" | awk -F"[ (]" 'BEGIN{rows=0;times=0} {rows+=$3;times+=$7} END{print "\nTotal rows: "rows,"\nTotal Times(min): "times/60"\n"}'
Total rows: 9990253
Total Times(min): 76.8903
[zhuxu@dbadb1 tmp]$
[/quote]
eg2:AWK列分组GRUP BY汇总SUM:
[quote]
$head zx.log
2011-01-19 10
2011-01-19 10
2011-01-19 100
2011-01-19 1042
2011-01-19 10422
2011-01-19 1059
2011-01-19 1059
2011-01-19 10887
2011-01-19 1140
2011-01-19 11724
$awk '{name[$1]+=$2;sum+=$2} END {for(i in name) print i,name[i];print "=====> Total:",sum,"<=====";}' zx.log | sort -k1 -M
2011-01-19 496582
2011-01-20 1039690
2011-01-21 364867
2011-01-22 1200747
2011-01-23 112981
2011-01-24 465766
2011-01-25 1081170
2011-01-26 1111863
2011-01-27 335430
2011-01-28 450190
2011-01-29 120003
2011-01-30 99402
2011-01-31 262238
2011-02-01 240861
2011-02-02 181618
2011-02-03 145767
2011-02-04 133216
2011-02-05 100355
2011-02-06 99856
2011-02-07 138638
2011-02-08 142822
2011-02-09 511951
2011-02-10 496962
2011-02-11 669015
2011-02-12 1750215
2011-02-13 629162
=====> Total: 12381367 <=====
[/quote]
http://chenxu.yo2.cn/articles/shell_awk_if.html