Skip to content

Instantly share code, notes, and snippets.

@GitSumito
Created July 12, 2017 10:54
Show Gist options
  • Save GitSumito/565a603534565d00a3f2df9634bb1dc7 to your computer and use it in GitHub Desktop.
Save GitSumito/565a603534565d00a3f2df9634bb1dc7 to your computer and use it in GitHub Desktop.
アクセスログから任意のランキングを作る汎用的なワンライナー ref: http://qiita.com/S-T/items/73b2bb095c1b81e9337d
perl -ne 'next unless(/★単純にgrepするキーワード★/);/★集計単位★/;$counts{$1}++;END{for(sort keys %counts){print "$_ $counts{$_}\n"}}' access_log
$ perl -ne 'next unless(/Googlebot/);/2017:(\d\d)/;$counts{$1}++;END{for(sort keys %counts){print "$_ $counts{$_}\n"}}' access_log
03 1
04 11
05 17
06 36
07 20
08 36
09 30
10 33
11 54
12 45
13 62
14 23
15 32
16 38
17 24
18 15
$ perl -ne 'next unless(/Safari/);/2017:(\d\d)/;$counts{$1}++;END{for(sort keys %counts){print "$_ $counts{$_}\n"}}' access_log
03 89
04 1982
05 6149
06 15110
07 18474
08 17452
09 14082
10 11929
11 11365
12 12830
13 9830
14 16637
15 19439
16 19432
17 25928
18 22898
perl -ne 'next unless(/Googlebot/);/^(\S+)/;$counts{$1}++;END{for(sort keys %counts){print "$_ $counts{$_}\n"}}' access_log
66.249.66.205 1
66.249.71.143 1
66.249.71.145 2
66.249.71.147 2
66.249.71.73 182
66.249.71.75 106
66.249.71.76 1
66.249.71.77 56
66.249.71.77, 1
66.249.71.78 1
66.249.79.35 48
66.249.79.39 25
66.249.79.61 51
$ perl -ne 'next unless(//);/(\/js\/v2\/\w+)/;$counts{$1}++;END{for(sort keys %counts){print "$_ $counts{$_}\n"}}' access_log
95215
/js/v2/com 19069
/js/v2/fb 63491
/js/v2/pc 27632
/js/v2/old 26
/js/v2/smartphone 9392
END{集計処理}
/★集計単位★/;$counts{$1}++;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment