grep expression

Off-topic chat. Post your favorite mod_rewrite jokes here!

grep expression

Postby twikkistep » Tue Nov 28, 2006 5:16 am

As I suppose the same expressions for mod_rewrite work for grep as well, I'm wondering if if you can help me to construct the following question:

Code: Select all
example.com;20061128135608;37781965;www.example.com;GET /code/media/module1/module2/myfile.mp3 HTTP/1.1


I would like to grep out the important bits of this custom apache log. Namely, I would like to get everything that has a certain "code" word, "module1" word and "module2" word in it's line. How would one go over this?

Thanks in advance for any help!

-- TS
twikkistep
 
Posts: 24
Joined: Wed Nov 09, 2005 3:35 am

Postby richardk » Tue Nov 28, 2006 9:23 am

Does it run through it line by line? Then you'd just need soemthing like
Code: Select all
(code|module1|module2)
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby twikkistep » Tue Nov 28, 2006 10:59 am

Hi Richard,

Yes, it runs through it line by line, but the code and modules need to be at a specific place, like:

Code: Select all
example.com;20061128135608;37781965;www.example.com;GET /*/media/*/*/myfile.mp3 HTTP/1.1


so I want to seek between GET & media, and after media - 2 entries, divided by a slash ...
twikkistep
 
Posts: 24
Joined: Wed Nov 09, 2005 3:35 am

Postby richardk » Tue Nov 28, 2006 3:34 pm

Like this?
Code: Select all
;GET\s/([^/]+)/media/([^/]+)/([^/]+)/myfile\.mp3\sHTTP/


If myfile.mp3 changes you'll want to replace it with
Code: Select all
[^/]+

for any file or
Code: Select all
[^/]+\.mp3

for any .mp3 file.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Almost Anything Goes

Who is online

Users browsing this forum: No registered users and 5 guests

cron