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 7879655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:56:53+00:00 2026-06-03T03:56:53+00:00

I have a master file which is the one which will constantly be updated

  • 0

I have a master file which is the one which will constantly be updated and a file which is created every minute. I want to be able to compare the new file which is created every minute to the already existing master file. So far I’ve got:

with open("jobs") as a:
   new = a.readlines()

count=0
for item in new:
   new[count]=new[count].split(",")
   count+=1

This will allow me to compare the first index([0] of each line in my master file. Now at this point I start to confuse myself. I’m guessing it would be something along the lines of:

counter=0
for item in new:
    if new[counter][0] not in master:
        end = open("end","a")
        end.write(str(new[counter]) + "\n")
        counter+=1
        end.close()
    else:
         REPLACE LINES THAT ALREADY EXIST IN MASTER FILE WITH NEW LINE

The IDs won’t necessarily be in the same order every time the new file comes in and the new file may contains more entries than the master file at some point.

If I haven’t made sense or missed some information out then please let me know and I’ll try and clarify. 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-03T03:56:55+00:00Added an answer on June 3, 2026 at 3:56 am

    Sounds like a csv problem to me.

    unfortunately, it is not clear from your question, if you want to modify the masterfile itself, an out-file, or both.
    this does the second (it takes a masterfile and an updatefile, both in csv format, and prints the merged thing unsorted to an out-file). If this is not what you want, or if you got data comma-seperated, but without fieldnames on top, change as you need, should be easy enough.

    import csv
    with open("master.csv") as m, open("update.csv") as u, open("out.csv", "w") as o:
        master = { line['ID']: line for line in csv.DictReader(m) }
        update = { line['ID']: line for line in csv.DictReader(u) }
        master.update(update)
        fields = csv.DictReader(open("master.csv")).fieldnames
        out = csv.DictWriter(o, fields)
        out.writeheader()
        out.writerows(master.values())
    

    with master.csv as such:

    ID,Name,Foo,Bar,Baz,Description
    1000001,Name here:1,1001,1,description here
    1000002,Name here:2,1002,2,description here
    1000003,Name here:3,1003,3,description here
    1000004,Name here:4,1004,4,description here
    1000005,Name here:5,1005,5,description here
    1000006,Name here:6,1006,6,description here
    1000007,Name here:7,1007,7,description here
    1000008,Name here:8,1008,8,description here
    1000009,Name here:9,1009,9,description here
    

    and update.csv as such:

    ID,Name,Foo,Bar,Baz,Description
    1000003,UPDATED Name here:3,1003,3, UPDATED description here
    1000010,NEW ITEM Name here:9,1009,9,NEW ITEM description here 
    

    it outputs to out.csv:

    ID,Name,Foo,Bar,Baz,Description
    1000010,NEW ITEM Name here:9,1009,9,NEW ITEM description here ,
    1000008,Name here:8,1008,8,description here,
    1000009,Name here:9,1009,9,description here,
    1000006,Name here:6,1006,6,description here,
    1000007,Name here:7,1007,7,description here,
    1000004,Name here:4,1004,4,description here,
    1000005,Name here:5,1005,5,description here,
    1000002,Name here:2,1002,2,description here,
    1000003,UPDATED Name here:3,1003,3, UPDATED description here,
    1000001,Name here:1,1001,1,description here,
    

    Note that the order is not preserved (not clear from question if neccessary). But it is fast and clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Master Page which has an associated css file. On one of
I have a master build file which is calling other build.xml files of different
I have two files: master/newsletter1/file.html master/newsletter2/file.html newsletter1/file.html has a lot of new changes that
I have master branch of the project. Then I want to add a new
I have a repo that I have a master branch which will end up
on my master page, I have referenced jquery file. I am doing simple hover
I have a matlab script, lets call it master.m, that loads a file called
I have two tables that need to be updated, Master and Identifiers: Master --MasterID
I have 2 asp.net web applications, one of which is the main application and
I have a class which acts as a simple crawler and I want to

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.