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.
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