ログファイルの中から特定の文字列を抽出したい

```
$ cat sample.log
127.0.0.1 - - [21/Feb/2013:00:06:20 +0900] "GET /feed/ HTTP/1.0" 304 - "-" "livedoor FeedFetcher/0.01 (http://reader.livedoor.com/; 1 subscriber)"
127.0.0.1 - - [21/Feb/2013:00:06:26 +0900] "GET / HTTP/1.0" 200 17702 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
127.0.0.1 - - [21/Feb/2013:00:07:29 +0900] "GET / HTTP/1.0" 200 17702 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
127.0.0.1 - - [21/Feb/2013:00:20:51 +0900] "POST /wp-cron.php?doing_wp_cron=1361373651.0959939956665039062500 HTTP/1.0" 200 - "-" "WordPress/3.5.1; http://slothlibrary.com"
127.0.0.1 - - [21/Feb/2013:00:20:51 +0900] "GET /12/ HTTP/1.0" 200 27053 "http://slothlibrary.com/12/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; MRA 6.0 (build 5993); MRA 8.0 (build 5784); InfoPath.2)"
127.0.0.1 - - [21/Feb/2013:00:20:55 +0900] "POST /wp-comments-post.php HTTP/1.0" 302 - "http://slothlibrary.com/12/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; MRA 6.0 (build 5993); MRA 8.0 (build 5784); InfoPath.2)"
127.0.0.1 - - [21/Feb/2013:00:20:57 +0900] "GET /12/ HTTP/1.0" 200 27122 "http://slothlibrary.com/12/#comment-218" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; MRA 6.0 (build 5993); MRA 8.0 (build 5784); InfoPath.2)"
127.0.0.1 - - [21/Feb/2013:00:33:19 +0900] "GET /robots.txt HTTP/1.0" 200 59 "-" "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)"
127.0.0.1 - - [21/Feb/2013:00:33:29 +0900] "GET /category/developer HTTP/1.0" 301 - "-" "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)"
127.0.0.1 - - [21/Feb/2013:00:33:36 +0900] "GET /category/developer/ HTTP/1.0" 200 14096 "-" "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)"
127.0.0.1 - - [21/Feb/2013:00:33:47 +0900] "GET /category/wordpress HTTP/1.0" 301 20 "-" "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)"
127.0.0.1 - - [21/Feb/2013:00:33:54 +0900] "GET /category/wordpress/ HTTP/1.0" 200 3415 "-" "Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)"
127.0.0.1 - - [21/Feb/2013:00:44:44 +0900] "GET /feed/ HTTP/1.0" 200 2843 "-" "Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; 5 subscribers; feed-id=11476985210332317360)"
127.0.0.1 - - [21/Feb/2013:00:45:41 +0900] "GET /wordpress_sakuravps_move/ HTTP/1.0" 200 7408 "http://slothlibrary.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17"
127.0.0.1 - - [21/Feb/2013:00:48:25 +0900] "GET / HTTP/1.0" 200 4677 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17"
127.0.0.1 - - [21/Feb/2013:00:48:28 +0900] "GET /wp-blog/index.php HTTP/1.0" 301 20 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17"
127.0.0.1 - - [21/Feb/2013:00:48:28 +0900] "GET /wp-blog/ HTTP/1.0" 404 2116 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17"
```
試しにこのファイルから、Mozillaという文字だけを抜き出す

```
$ cat sample.log | awk 'match($0, /Mozilla\/[0-9]+/) { print substr($0, RSTART, RLENGTH) }'
Mozilla/4
Mozilla/4
Mozilla/4
Mozilla/4
Mozilla/4
Mozilla/5
Mozilla/5
Mozilla/5
Mozilla/5
Mozilla/5
Mozilla/5
Mozilla/5
Mozilla/5
Mozilla/5
```

数出したい場合は、以下の感じでOK

```
$ cat sample.log | awk 'match($0, /Mozilla\/[0-9]+/) { print substr($0, RSTART, RLENGTH) }' | awk -F '/' '{print $2}' | sort | uniq -c
   5 4
   9 5
```