How to count differences between two files on linux?

后端 未结 7 541
一整个雨季
一整个雨季 2020-12-23 13:45

I need to work with large files and must find differences between two. And I don\'t need the different bits, but the number of differences.

To find the number of dif

相关标签:
7条回答
  • 2020-12-23 14:24

    If you're dealing with files with analogous content that should be sorted the same line-for-line (like CSV files describing similar things) and you would e.g. want to find 2 differences in the following files:

    File a:    File b:
    min,max    min,max
    1,5        2,5
    3,4        3,4
    -2,10      -1,1
    

    you could implement it in Python like this:

    different_lines = 0
    with open(file1) as a, open(file2) as b:
        for line in a:
            other_line = b.readline()
            if line != other_line:
                different_lines += 1
    
    0 讨论(0)
提交回复
热议问题