[Tutor] searching out keywords...

Bob X bobx@linuxmail.org
Sat, 09 Mar 2002 00:11:30 +0800


I have to monitor some hefty (min 40MB) log files. I have a list of keywords that I want to search for and then write those lines out to a different file. Basically I want to do this.

1. run the py file with the log file as an ARG on the command line.
2. have it search that file for keywords
3. insert the lines that the keywords appears on into a different file

>From looking around a bit I have this...but:

import sys, string

# open the file to read
inp = open(sys.argv[1],"r")
outp = open("badwords.txt","w")

# create a keyword list
kw = ["sex","teen"]

# read the file in and search for keywords
for kw in inp.readlines():
  outp.write(line)   # needs to go to outp file
print "finished text processing"

# close em up
inp.close()
outp.close()

Help would be appreciated...I am learning wxPython as well and will put a gui on it once this is done.

Bob


-- 

Get your free email from www.linuxmail.org 


Powered by Outblaze