Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare two different files line by line and write the difference in third file - Python
    primarykey
    data
    text
    <p>I would like to compare two text files which have three columns each. One file has 999 rows and another has 757 rows. I want the different 242 rows to be stored in a different file. I created the first file (999 rows) using a random network generator (999 rows are edges with third column being weight between first, second columns - source, destination nodes).</p> <p><strong>File Format - Files 1, 2</strong></p> <pre><code>1 3 1 16 36 1 </code></pre> <p>I have tried</p> <p><a href="https://stackoverflow.com/questions/4544709/compare-two-files-line-by-line-and-generate-the-difference-in-another-file">Compare two files line by line and generate the difference in another file</a> and <a href="https://stackoverflow.com/questions/4078933/find-difference-between-two-text-files-with-one-item-per-line">find difference between two text files with one item per line</a> and <a href="http://www.daniweb.com/software-development/python/threads/124932/610058#post610058" rel="nofollow noreferrer">http://www.daniweb.com/software-development/python/threads/124932/610058#post610058</a></p> <p>neither worked for me.</p> <p>I think it is a problem of string comparison. I would like to compare the numbers in first column and second column. If they both are different, I want to write it to third file.</p> <p>Any help will be much appreciated!</p> <p><strong>Update</strong></p> <p>I am posting the following code that I tried after @MK posted his comment.</p> <pre><code>f = open("results.txt","w") for line in file("100rwsnMore.txt"): rwsncount += 1 line = line.split() src = line[0] dest = line[1] for row in file("100rwsnDeleted.txt"): row = row.split() s = row[0] d = row[1] if(s != src and d != dest): f.write(str(s)) f.write(' ') f.write(str(d)) f.write('\n') f.close() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload