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