[英]Filter apache files using linux
I'm trying to filter down a heap of apache log files to EXCLUDE all requests that have: 我正在尝试过滤掉一堆apache日志文件到EXCLUDE所有具有以下要求的请求:
/static/
(this is my images/js folder that I want to exclude) 模式/static/
(这是我要排除的images / js文件夹) 10.xxx.xxx.xxx
(where x is any number - I don't want internal requests included) 10.xxx.xxx.xxx
(其中x是任意数字 - 我不希望包含内部请求) "GET / HTTP/1.1" 200
- only want successes 除"GET / HTTP/1.1" 200
之外的任何响应 - 只需要成功 I have a folder containing multiple .gz files. 我有一个包含多个.gz文件的文件夹。 Is there a way to run a linux command that will do the proper filtering and save the results in a file called apache_log.txt? 有没有办法运行一个linux命令来执行正确的过滤并将结果保存在一个名为apache_log.txt的文件中?
I'm really limited in my linux knowledge so will appreciate any help greatly! 我的Linux知识非常有限,所以非常感谢任何帮助!
For each file *.gz, uncompress and filter out unwanted static and local, and filter wanted "GET 200", and append this in result file. 对于每个文件* .gz,解压缩并过滤掉不需要的静态和本地,并过滤所需的“GET 200”,并将其附加到结果文件中。
for f in *.gz ; do zcat $f | grep -v '/static/' | grep -v '10\.[0-9]\+\.\.[0-9]\+\.[0-9]\+' | grep 'GET / HTTP/1.1" 200' >> apache_log.txt ; done
Or on multiple lines. 或多行。
for f in *.gz
do
zcat $f \
| grep -v '/static/' \
| grep -v '10\.[0-9]\+\.\.[0-9]\+\.[0-9]\+' \
| grep 'GET / HTTP/1.1" 200' \
>> apache_log.txt
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.