Connecting Tech Pros Worldwide Help | Site Map

finding filename in log file

  #1  
Old October 6th, 2008, 12:31 PM
Newbie
 
Join Date: Oct 2008
Posts: 5
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.
  #2  
Old October 6th, 2008, 02:28 PM
bvdet's Avatar
Moderator
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,545

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing Web log Entry's for file downloads using ashx =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= answers 7 September 8th, 2008 06:55 AM
Find Paths in log text - How to? citizenkahn answers 0 March 23rd, 2006 08:05 PM
Double "Open/Save/Cancel/More Info" dialog when downloading text file from ASP.NET theyas answers 7 November 18th, 2005 10:41 AM
How to get the FileName and Path to which a StreamWriter is attached to? José Joye answers 5 November 15th, 2005 11:31 AM