Connecting Tech Pros Worldwide Forums | Help | Site Map

finding filename in log file

Newbie
 
Join Date: Oct 2008
Posts: 5
#1: Oct 6 '08
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.

bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,566
#2: Oct 6 '08

re: finding filename in log file


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