PYTHON - Comparing two different files; if a line containing an ID already exists then update else append the line
<p>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:</p>

<pre><code>with open("jobs") as a:
   new = a.readlines()

count=0
for item in new:
   new[count]=new[count].split(",")
   count+=1
</code></pre>

<p>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:</p>

<pre><code>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
</code></pre>

<p>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.</p>

<p>If I haven't made sense or missed some information out then please let me know and I'll try and clarify. Thanks.</p>
