Linux 比较两个文件并输出差异内容

Kevin 教程 1,056 次浏览 17条评论

问题描述:在 Linux 命令终端下对比 2 个文件内容,并分别显示它们之间的差异。

文件例子:

cat file1.txt
1
2
3
4
5
7

cat file2.txt
1
2
6
3
4
5
9
8

先直观查看下两个文件之间的差异对比。

diff -y file1.txt file2.txt
1                                                               1
2                                                               2
                                                              > 6
3                                                               3
4                                                               4
5                                                               5
7                                                             | 9
                                                              > 8

再用下面命令输出对比结果。

显示file1.txt文件里没有的内容。

grep -Fxvf file1.txt file2.txt
6
9
8

显示file2.txt文件里没有的内容。

grep -Fxvf file2.txt file1.txt
7

显示两个文件都有的相同内容。

grep -Fxf file1.txt file2.txt
1
2
3
4
5

评论列表

  1. #1

    Hi, very nice website, cheers!
    ——————————————————
    Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo.
    ——————————————————
    Check here: https://www.reliable-webhosting.com/

  2. #2

    acyclovir suppressive therapy for herpes https://www.herpessymptomsinmen.org/productacyclovir/

  3. #3

    when will lumigan become generic https://carepro1st.com/

  4. #4

    viagra pills viagra without doctor https://buszcentrum.com/

  5. #5

    amoxicillin sample request form https://amoxycillin1st.com/

  6. #6

    ivermectin for head lice dose https://ivermectin.webbfenix.com/

  7. #7

    pregnancy with clomid 1st use https://salemeds24.wixsite.com/clomid

  8. #8

    mefloquine vs hydroxychloroquine https://hydroxychloroquine.webbfenix.com/

  9. #9

    vidalista over counter walmart https://vidalista.mlsmalta.com/

  10. #10

    hydroxychloroquine and cardiovascular risk https://hydroxychloroquine.mlsmalta.com/

  11. #11

    best price cialis 20mg http://www.lm360.us/

  12. #12

    mexican vidalista pills https://vidalista.buszcentrum.com/

  13. #13

    viagra generics price http://droga5.net/

  14. #14

    coupon for hydroxychloroquine https://hhydroxychloroquine.com/

  15. #15

    is a good thing.

    http://ozemigration.com/

  16. #16

    ivermectin for heartworm treatment https://ivermectin.mlsmalta.com/

  17. #17

    order generic vidalista https://vidalista40mg.mlsmalta.com/

发表评论

电邮地址用于 Gravatar 头像显示,不会被公开可见。