By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

Log Search code is not working

P: n/a
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/ =-

Nov 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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/pydis...XT=long+necked

On Nov 18, 7:12 pm, "martin" <mar...@logs.comwrote:
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
....
Nov 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.