如何从日志中获取我网站上所有唯一PHP GET的列表?

In my log I have many lines that look like this:

mysitename.net 1.23.45.67 - - [10/Mar/2017:20:28:38 +0000] "GET /foldername/special/somefile.php HTTP/1.1" 200 2012

Is there any way to grep all the unique PHP GETs into a file, so I have a list of any/all files on the server that were accessed?

I tried:

grep -i "GET [\w]+.php" mylogfile.txt > results.txt

but it does not return any rows.

1个回答

For grep, i would do it like this:

$ a=$'mysitename.net 1.23.45.67 - - [10/Mar/2017:20:28:38 +0000] "GET /foldername/special/somefile.php HTTP/1.1" 200 2012' 
$ grep -Eo 'GET.*php' <<<"$a"
GET /foldername/special/somefile.php

Personally, especially in mac, i would go for perl -pe oneliner, since works the same in all platforms, using regex group matching with backreference.

In bellow example , the whole input string is divided in groups using parenthesis. Working with perl substitution (identical to sed) we can force perl to return to us only the third input group:

$ perl -pe 's/(.*)(GET )(.*.php)(.*)/\3/g' <<<"$a" #if you want to include also the GET in your results then modify last part like .../\2\3/g'
/foldername/special/somefile.php
doujiexi1824
doujiexi1824 Grep解决方案补充说
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问