Connecting Tech Pros Worldwide Help | Site Map

finding filename in log file

 
LinkBack Thread Tools Search this Thread
  #1  
Old October 6th, 2008, 11:31 AM
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, 01:28 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,439
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 Search this Thread
Search this Thread:

Advanced Search


Popular Articles

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 220,989 network members.