27.5.5 時間毎・所属毎のアクセス数を数える

次のプログラムは, 所属×時間の集計をします. shozoku-time.awk という名前のファイルで作ってください.

{
    split($4, dates, /:/); 
    # 13/Sep/2004:12:00:21 --> 13/Sep/2004, 12, 00, 21
    hour = dates[2];
    access[hour]++;
    if( /~a/ )   a[hour]++;
    if( /~c/ )   c[hour]++;
    if( /~e/ )   e[hour]++;
    if( /~g/ )   g[hour]++;
    if( /~j/ )   j[hour]++;
    if( /~l/ )   l[hour]++;
    if( /~m/ )   m[hour]++;
    if( /~n/ )   n[hour]++;
    if( /~p/ )   p[hour]++;
    if( /~s/ )   s[hour]++;
    if( /~t/ )   t[hour]++;
    if( /~u/ )   u[hour]++;
}

END{
    print "  hour\t all a c e g j l m n p s t u"
    for(h in access){
        printf("%2d\t %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
        h, access[h], a[h], c[h], e[h], g[h], j[h], l[h], m[h], n[h], p[h], s[h], t[h], u[h]);
    }
}

このプログラムを実行すると, 次のようになります.

promptawk -f shozoku-time.awk 24Mar | sort -n return2   hour all a c e g j l m n p s t u  0 9541, 403, 168, 123, 2591, 804, 183, 111, 30, 15, 1227, 2445, 9  1 7557, 67, 256, 125, 2500, 813, 94, 99, 8, 0, 1243, 1632, 2  2 4689, 110, 82, 96, 1289, 821, 244, 149, 13, 4, 560, 955, 8  3 3270, 22, 142, 17, 1040, 686, 22, 94, 2, 6, 395, 676, 3  4 1850, 26, 22, 13, 471, 562, 16, 92, 2, 1, 157, 331, 5  5 1162, 21, 21, 24, 271, 52, 59, 77, 8, 3, 215, 280, 1  6 1409, 4, 16, 16, 374, 66, 55, 22, 2, 5, 184, 529, 5  7 1355, 47, 69, 11, 365, 70, 10, 23, 5, 2, 241, 344, 0  8 2460, 67, 20, 25, 773, 130, 110, 129, 1, 9, 369, 573, 4  9 3178, 103, 36, 25, 1193, 175, 45, 44, 22, 10, 329, 834, 1 10 4587, 173, 42, 45, 1739, 195, 70, 58, 21, 3, 936, 873, 15 11 6426, 368, 315, 98, 2894, 154, 435, 173, 10, 2, 662, 758, 3 12 5787, 298, 220, 95, 2525, 258, 131, 127, 10, 3, 973, 741, 4 13 6801, 195, 138, 98, 2960, 186, 172, 229, 23, 130, 909, 1311, 1 14 5427, 87, 185, 93, 1676, 225, 191, 213, 29, 4, 1193, 875, 3 15 5988, 348, 186, 120, 1950, 202, 236, 321, 7, 0, 1012, 794, 1 16 6300, 142, 208, 159, 1858, 168, 142, 246, 18, 3, 985, 1756, 6 17 6479, 154, 247, 86, 1506, 198, 148, 310, 40, 17, 1001, 1951, 4 18 7199, 51, 201, 51, 1217, 279, 141, 223, 42, 25, 848, 3604, 8 19 5221, 77, 516, 84, 1454, 192, 50, 275, 21, 16, 991, 942, 3 20 3638, 140, 303, 38, 1254, 70, 193, 80, 19, 3, 570, 754, 3 21 6498, 106, 308, 139, 2114, 266, 409, 203, 43, 85, 1227, 901, 0 22 6812, 110, 230, 124, 2535, 273, 171, 269, 45, 2, 1090, 1291, 3 23 8464, 119, 427, 113, 2747, 382, 225, 158, 39, 9, 1427, 1530, 7

プログラムの解説