- 如何从日志中获取我网站上所有唯一PHP GET的列表？
In my log I have many lines that look like this:
mysitename.net 220.127.116.11 - - [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?
grep -i "GET [\w]+.php" mylogfile.txt > results.txt
but it does not return any rows.
For grep, i would do it like this:
$ a=$'mysitename.net 18.104.22.168 - - [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