linux对比两个文件中的ip,Linux对比2个文件不同内容之diff命令

案例1:

先建立两个文件diff1.txt和diff2.txt:

31c5900ece659ff1884af89356265c32.png

[root@zcwyou ~]# cat diff1.txt

1a

2

3

4

[root@zcwyou ~]# cat diff2.txt

1

2b

3c

4

5

6

7

8

执行一下比较:

[root@zcwyou ~]# diff diff1.txt diff2.txt

输出结果如下:

1,3c1,3

< 1a

< 2

< 3

1

2b

3c

4a5,8

5

6

7

8

1,3c1,3表示有1行相当(第4行),3行c(c表示修改过,d表示删除,a表示增加),它们的行号范围是1-3。然后列出不同的地方。

4a5,8,表示有4行是增加的,行号是5-8。

案例2:

再建立两个文件:

文件1内容:cisco1.txt

dffb876cbced86ca66a33d5e51c74b20.png

enable

conf t

hostname ZS_121_201_122_120

no ip domain-lookup

vlan 1000

interface Vlan 1000

ip address 12.21.12.12 255.255.255.0

no sh

ip route 0.0.0.0 0.0.0.0 12.21.12.1

文件2内容:cisco2.txt

enable

conf t

hostname ZS_121_201_122_120

no ip domain-lookup

vlan 100

vlan 1000

interface Vlan 1000

ip address 12.21.12.12 255.255.255.0

ip route 0.0.0.0 0.0.0.0 12.21.12.13

执行比较:

[root@zcwyou ~]# diff cisco1.txt cisco2.txt -y -w -W 50

对比结果如下:

enable enable

conf t conf t

hostname ZS_121_201_1 hostname ZS_121_201_1

no ip domain-lookup no ip domain-lookup

> vlan 100

>

vlan 1000 vlan 1000

interface Vlan 1000 interface Vlan 1000

ip address 12.21.12. ip address 12.21.12.

no sh | ip route 0.0.0.0 0.0.

ip route 0.0.0.0 0.0. |

eaece6d8f14e85eb7ec9d9ff8b7ab234.png

表示右比左多,

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值