Log Search code is not working

Discussion in 'Python' started by martin, Nov 19, 2007.

  1. martin

    martin Guest

    Hello,

    I need some help with my job assignment and the code that is not working. I am to search all log files and print out how many "name"
    used "fields" in all the logs? I have a list of about 50 names and 50 fields and now i need search and count.

    How to search regardless of the case?

    This what I wrote it does not work or it just ran so slow that I had to stop it.

    Oh and I have about 100 web logs to search.


    import os

    name = [
    'name1',
    'name2',
    'name3',
    'name4',
    'name5'
    ]

    fields = [
    'field1',
    'field2',
    'field3',
    'field4'
    ]

    dict = {}

    for (dirpath, dirnames, filenames) in os.walk('path'):
    for f in filenames:
    myFile = file(os.path.join(dirpath,f))
    for lines in myFile:
    lines = lines.split()
    for each_name in name:
    for each_field in fields:
    for each_line in lines:
    if each_name in each_line:
    if each_field in each_line:
    if not dict.has_key(each_name + ':' + each_field):
    dict[each_name + ':' + each_field] = 1
    else: dict[each_name + ':' + each_field] = dict[each_name + ':' + each_field] + 1
    print dict

    Any help would be appreciated or if there is a better way to code this?


    --------------= Posted using GrabIt =----------------
    ------= Binary Usenet downloading made easy =---------
    -= Get GrabIt for free from http://www.shemes.com/ =-
     
    martin, Nov 19, 2007
    #1
    1. Advertising

  2. This might be a perfect application for nucular.

    http://nucular.sourceforge.net

    If you need help using it I can help a bit by email (not
    on the list).

    If you want to build your own solution, what you have might
    be fixable, but you need to take out the lowest level loops
    by using dictionaries and the dictionary.has_key(...) method
    instead of looping over lists.

    -- Aaron Watters

    ===
    http://www.xfeedme.com/nucular/pydistro.py/go?FREETEXT=long necked

    On Nov 18, 7:12 pm, "martin" <> wrote:
    > Hello,
    >
    > I need some help with my job assignment and the code that is not working. I am to search all log files and print out how many "name"
    > used "fields" in all the logs? I have a list of about 50 names and 50 fields and now i need search and count.
    >
    > How to search regardless of the case?
    >
    > This what I wrote it does not work or it just ran so slow that I had to stop it.
    >
    > Oh and I have about 100 web logs to search.
    >
    > import os
    >

    ....
     
    Aaron Watters, Nov 19, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henrik_the_boss
    Replies:
    0
    Views:
    2,715
    Henrik_the_boss
    Nov 5, 2003
  2. =?Utf-8?B?VG9tIFdpbmdlcnQ=?=

    My.Log.Writeexception not writing to Application Event Log.

    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=, Jan 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    2,417
    =?Utf-8?B?VG9tIFdpbmdlcnQ=?=
    Jan 20, 2006
  3. vj
    Replies:
    0
    Views:
    707
  4. Tom Wingert
    Replies:
    0
    Views:
    377
    Tom Wingert
    Jan 12, 2006
  5. Abby Lee
    Replies:
    5
    Views:
    481
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page