Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 6th, 2008, 12:31 PM
Newbie
 
Join Date: Oct 2008
Posts: 5
Default finding filename in log file

I have a log file with this line
lisa.sm.luth.se - - [15/Aug/2005:02:42:12 +0200] "GET //csee/csn/include/div.cfg HTTP/1.0" 200 447 "-" "-"
I want to extract the filename between GET and HTTP. Is there a function i can use. I have heard split works but i have no idea. Thanks in advance.
Reply
  #2  
Old October 6th, 2008, 02:28 PM
bvdet's Avatar
Expert
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,221
Default

Here's two ways - re and string slicing.
Expand|Select|Wrap|Line Numbers
  1. import re
  2.  
  3. s = 'lisa.sm.luth.se - - [15/Aug/2005:02:42:12 +0200] "GET //csee/csn/include/div.cfg HTTP/1.0" 200 447 "-" "-"'
  4.  
  5. patt = re.compile(r"GET (.+) HTTP")
  6. m = patt.search(s)
  7. if m:
  8.     print m.group(1)
  9.  
  10. print s[s.index("GET ")+4:s.index(" HTTP")]
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles