I want to get the “GET” queries from my server logs.
For example, this is the server log
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:32:27] code 404, message File not fo$
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:32:27] "GET /hello HTTP/1.1" 404 -
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:41:57] code 404, message File not fo$
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:41:57] "GET /ss HTTP/1.1" 404 -
When I try with simple grep or awk,
Adi:~ adi$ awk '/GET/, /HTTP/' serverlogs.txt
it gives out
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:32:27] "GET /hello HTTP/1.1" 404 -
1.0.0.127.in-addr.arpa - - [10/Jun/2012 15:41:57] "GET /ss HTTP/1.1" 404 -
I just want to display : hello and ss
Is there any way this could be done?
Assuming you have gnu grep, you can use perl-style regex to do a positive lookbehind:
If you don’t have gnu grep, then I’d advise just using sed:
If you happen to have gnu sed, that can be greatly simplified:
The bottom line here is, you certainly don’t need pipes to accomplish this.
greporsedalone will suffice.