LoginSignup
1
2

More than 5 years have passed since last update.

Apacheのアクセスログから必要な情報を取り出す

Last updated at Posted at 2018-01-03

概要

Apacheのアクセスログから必要な情報のみ、
取り出して集計する必要があったのでメモしておく。

awk,gawkコマンドでの加工例

awk
$ cat access_log.20171227 \
 | grep 'GET /hoge/' \
 | awk 'BEGIN { OFS = "¥t" }{print($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)}'
gawk
$ cat access_log.20171227 \
 | grep 'GET /hoge/' \
 | gawk -v FPAT='([^ ]+)|(\"[^\"]+\")' '{ \
   print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 \
 }'
gawk
$ cat access_log.20171227 \
 | grep 'GET /hoge/' \
 | gawk 'BEGIN { OFS = "¥t" }{ \
   patsplit($0,arr,"([^ ]+)|(\"[^\"]+\")|(\\[[^\\]]+\\])"); \
   session_id="\""arr[12]"\""; \
   ip="\""arr[1]"\""; \
   time=substr(arr[4],2,(length(arr[4])-2)); \
   url=arr[5]; \
   user_agent=arr[9]; \
   host=arr[10]; \
   print(session_id, time, url, host, ip, user_agent) \
 }'

参考サイト

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2