nested for loop

Posted by Gary on Stack Overflow See other posts from Stack Overflow or by Gary
Published on 2010-05-28T20:21:07Z Indexed on 2010/05/31 3:02 UTC
Read the original article Hit count: 505

Filed under:
|
|

Hello, Just learning Python and trying to do a nested for loop. What I'd like to do in the end is place a bunch of email addresses in a file and have this script find the info, like the sending IP of mail ID. For now i'm testing it on my /var/log/auth.log file

Here is my code so far:

#!/usr/bin/python

# this section puts emails from file(SpamEmail) in to a array(array)
in_file = open("testFile", "r")
array = in_file.readlines()
in_file.close()

# this section opens and reads the target file, in this case 'auth.log'
log = open("/var/log/auth.log", "r")
auth = log.readlines()

for email in array:
    print "Searching for " +email,
    for line in auth:
         if line.find(email) > -1:
                about = line.split()
                print about[0],
    print

Inside 'testfile' I have the word 'disconnect' cause I know it's in the auth.log file. It just doesn't find the word 'disconnect'. In the line of "if line.find(email) > -1:" i can replace email and put "disconnect" the scripts finds it fine.

Any idea? Thanks in advance. Gary

© Stack Overflow or respective owner

Related posts about python

Related posts about loops