Possible Duplicate:
Compare two different files line by line and write the difference in third file - Python
The logic in my head works something like this... for line in import_file check to see if it contains any of the items in Existing-user-string-list if it contains any one of the items from that list then delete that line for the file.
filenew = open('new-user', 'r')
filexist = open('existing-user', 'r')
fileresult = open('result-file', 'r+')
xlines = filexist.readlines()
newlines = filenew.readlines()
for item in newlines:
if item contains an item from xlines
break
else fileresult.write(item)
filenew.close()
filexist.close()
fileresult.close()
I know this code is all jacked up but perhaps you can point me in the right direction.
Thanks!
Edit ----
Here is an example of what is in my existing user file....
allyson.knanishu
amy.curtiss
amy.hunter
amy.schelker
andrea.vallejo
angel.bender
angie.loebach
Here is an example of what is in my new user file....
aimee.neece,aimee,neece,aimee.neece@faculty.asdf.org,aimee neece,aimee neece,"CN=aimee neece,OU=Imported,dc=Faculty,dc=asdf,dc=org"
alexis.andrews,alexis,andrews,alexis.andrews@faculty.asdf.org,alexis andrews,alexis andrews,"CN=alexis andrews,OU=Imported,dc=Faculty,dc=asdf,dc=org"
alice.lee,alice,lee,alice.lee@faculty.asdf.org,alice lee,alice lee,"CN=alice lee,OU=Imported,dc=Faculty,dc=asdf,dc=org"
allyson.knanishu,allyson,knanishu,allyson.knanishu@faculty.asdf.org,allyson knanishu,allyson knanishu,"CN=allyson knanishu,OU=Imported,dc=Faculty,dc=asdf,dc=org"
New code from @mikebabcock ... thanks.
outfile = file("result-file.txt", "w")
lines_to_check_for = [ parser(line) for line in file("existing-user.txt", "r") ]
for line in file("new-user.txt", "r"):
if not parser(line) in lines_to_check_for:
outfile.write(line)
Added an import statement for the parser... I am receiving the following error...
C:\temp\ad-import\test-files>python new-script.py
Traceback (most recent call last):
File "new-script.py", line 7, in <module>
lines_to_check_for = [ parser(line) for line in file("existing-user.txt", "r
") ]
TypeError: 'module' object is not callable
Thanks!