内の値に応じて行を抽出する awkで[](カギカッコ)内の値に応じて行を抽出する](/images/6/c/d/c/1/6cdc18c760e85ac7a170c62abc2792a2d09cc279-20150925000002.jpeg)
仕事で、Apacheのログ・ファイルから内に記述されている応答時間で、時間のかかっているログのみを抽出するといった対応があった。
で、とりあえず〇〇秒以上のログだけを抽出するような対応をしたので、その備忘。
対応としては、以下のようにデリミタにを指定して、その中の値が〇〇以上のログだけを抽出するようにした。
awk -F '[][]' '$4 >= 〇〇' ログファイルPATH
[root@test-centos7 ~]# cat /var/log/httpd/access_log-20150906
::1 - - [02/Aug/2015:15:33:22 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 (internal dummy connection)" [0]
::1 - - [02/Aug/2015:15:33:22 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 (internal dummy connection)" [20]
::1 - - [02/Aug/2015:15:33:22 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 (internal dummy connection)" [0]
::1 - - [02/Aug/2015:15:33:22 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 (internal dummy connection)" [50]
::1 - - [02/Aug/2015:15:33:22 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 (internal dummy connection)" [10]
[root@test-centos7 ~]# awk -F '[][]' '$4 >= 20' /var/log/httpd/access_log-20150906
::1 - - [02/Aug/2015:15:33:22 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 (internal dummy connection)" [20]
::1 - - [02/Aug/2015:15:33:22 +0900] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16 (internal dummy connection)" [50]