Log Search code is not working

M

martin

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/ =-
 
A

Aaron Watters

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

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
....
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top