473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Log Search code is not working

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
1 1228
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
0
by: Hriday | last post by:
Hi there, I am working on a web application in ASP.NET My web server and AD machine are in the same domain but located on diffrent phisical machine, I am not able to search user's info by the...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
2
by: princymg | last post by:
I want to search a file from server and want to copy it to the local disk. how it is done? This is working if the file is in my hard disk itself.But not when it comes to server. If i map the server...
12
by: iahamed | last post by:
Hi Everyone, I got two parts of my advance search to work, I am running out of Logic to connect the third. My mind is in swing! Pleaseeeeeeeee Help me. I have 3 Fiels to search, the First two...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.