linux 高效对比两个的不同行

  |   0 评论   |   7 浏览

    #!/bin/bash
    
    # 用法:sh fast_diff.sh file1.txt file2.txt
    
    sort "$1" > /tmp/file1_sorted
    
    sort "$2" > /tmp/file2_sorted
    
    echo "只在 $1 中存在的行:"
    
    comm -23 /tmp/file1_sorted /tmp/file2_sorted
    
    #echo
    
    #echo "只在 $2 中存在的行:"
    
    #comm -13 /tmp/file1_sorted /tmp/file2_sorted
    
    # 清理临时文件
    
    rm /tmp/file1_sorted /tmp/file2_sorted
    

    评论

    发表评论

    validate