Comparison function that compares two text files in Unix

前端 未结 5 2066
走了就别回头了
走了就别回头了 2021-02-07 12:54

I was wondering if anyone could tell me if there is a function available in unix, bash that compares all of the lines of the files. If they are different it should output true/f

5条回答
  •  清歌不尽
    2021-02-07 13:34

    You could do an md5 on the two files, then compare the results in bash.

    No Unix box here to test, but this should be right.

    #!/bin/bash
    
    md1=$(md5 file1);
    md2=$(md5 file2);
    
    if [ $md1 -eq $ $md2 ]; then
      echo The same
    else
      echo Different
    fi
    

提交回复
热议问题