Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:29:53+00:00 2026-06-12T20:29:53+00:00

Possible Duplicate: Compare two different files line by line and write the difference in

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:29:54+00:00Added an answer on June 12, 2026 at 8:29 pm

    I presume this is what you want to do:

    outfile = file("outfile.txt", "w")
    lines_to_check_for = [ line for line in file("list.txt", "r") ]
    for line in file("testing.txt", "r"):
        if not line in lines_to_check_for:
            outfile.write(line)
    

    This will read all the lines in list.txt into an array, and then check each line of testing.txt against that array. All the lines that aren’t in that array will be written out to outfile.txt.

    Here’s an updated example based on your new question:

    newusers = file("newusers.txt", "w")
    existing_users = [ line for line in file("users.txt", "r") ]
    for line in file("testing.txt", "r"):
        # grab each comma-separated user, take the portion left of the @, if any
        new_users = [ entry.split["@"](0) for entry in line.split(",") ]
        for user in new_users:
            if not user in existing_users:
                newusers.write(user)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to compare two dates to find time difference in SQL Server
Possible Duplicate: How to compare two arraylist? I have two String ArrayLists of different
Possible Duplicate: How to compare two hashmaps in java? Hi i have two different
Possible Duplicate: Compare dates in java I am getting two dates from server in
Possible Duplicate: MVC3 custom validation: compare two dates I am trying to make a
Possible Duplicate: compare two ip with C# How to compare two IP? By compare
Possible Duplicate: Differences in string compare methods in C# Is there any difference between
Possible Duplicate: Best way to determine if two path reference to same file in
Possible Duplicate: How to compare 2 files fast using .NET? How can I compare
Possible Duplicate: How does Python compare string and int? Can any one explain the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.