Copy differences between two files in unix

后端 未结 3 2028
南旧
南旧 2020-12-21 23:45

Firstly, which is the best and fastest unix command to get only the differences between two files ? I tried using diff to do it (below).

I tried the answer given by

相关标签:
3条回答
  • The -y option to diff makes it produce a "side by side" diff, which is why you have the spaces. Try -u 0 for the unified format with zero lines of context. That should print:

    +Glad to be here:)
    

    The plus means the line was added, whereas a minus means it was removed.

    0 讨论(0)
  • 2020-12-22 00:22

    Another way to get diff is by using awk:

    awk 'FNR==NR{a[$0];next}!($0 in a)' file1 file2
    

    Though I must admit that I haven't run any benchmarks and can't say which is the fastest solution.

    0 讨论(0)
  • 2020-12-22 00:35
    diff -a --suppress-common-lines -y file1.txt file2.txt|tr 'a >' '' |awk '{print $1}' >>file3.txt 
    
    0 讨论(0)
提交回复
热议问题