linux diff comm 比较文件内容

预先对经比较的文件进行sort排序

comm
-12 就只显示在两个文件中都存在的行
-23 显示在的文件中出现而未在的文件中出现的行

comm -23 2.txt 1.txt #找出文件2中有,文件1中没有的行

diff

Linux diff command help and examples

[root@localhost test3]# diff log2014.log log2013.log 
3c3       #####log2014.log和log20143log文件在第3行内容有所不同
< 2014-03
---
> 2013-03
8c8       #####log2014.log和log20143log文件在第8行内容有所不同
< 2013-07
---
> 2013-08
11,12d10  #####第一个文件比第二个文件多了第11和12行
< 2013-11
< 2013-12
  • -y或--side-by-side  以并列的方式显示文件的异同之处。
  • -W<宽度>或--width<宽度>  在使用-y参数时,指定栏宽。
[root@localhost test3]# diff log2014.log log2013.log  -y -W 50
2013-01                 2013-01
2013-02                 2013-02
2014-03               | 2013-03            #  "|"表示前后2个文件内容有不同
2013-04                 2013-04
2013-05                 2013-05
2013-06                 2013-06
2013-07                 2013-07
2013-07               | 2013-08
2013-09                 2013-09
2013-10                 2013-10
2013-11               <                    #  "<"表示后面文件比前面文件少了1行内容
2013-12               <
[root@localhost test3]# diff log2013.log log2014.log  -y -W 50
2013-01                 2013-01
2013-02                 2013-02
2013-03               | 2014-03
2013-04                 2013-04
2013-05                 2013-05
2013-06                 2013-06
2013-07                 2013-07
2013-08               | 2013-07
2013-09                 2013-09
2013-10                 2013-10
                      > 2013-11
                      > 2013-12            #  ">"表示后面文件比前面文件多了1行内容
                                           #谁尖谁多一条,箭头指向多的那条记录

output

左边几个点,文件几

 "2,4c2,4" means: "Lines 2 through 4 in the first file need to be changed to match lines 2 through 4 in the second file." It then tells us what those lines are in each file:

 

Here, the output is telling us "After line 2 in the first file, a line needs to be added: line 3 from the second file." It then shows us what that line is. 

Here, the output is telling us "You need to delete line 4 in the first file so that both files sync up同步 at line 3." It then shows us the contents of the line that needs to be deleted. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值