finding filename in log file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cooolsson
    New Member
    • Oct 2008
    • 5

    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.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Here's two ways - re and string slicing.[code=Python]import re

    s = 'lisa.sm.luth.s e - - [15/Aug/2005:02:42:12 +0200] "GET //csee/csn/include/div.cfg HTTP/1.0" 200 447 "-" "-"'

    patt = re.compile(r"GE T (.+) HTTP")
    m = patt.search(s)
    if m:
    print m.group(1)

    print s[s.index("GET ")+4:s.inde x(" HTTP")][/code]

    Comment

    Working...