智传网优云课堂,专注分享IT技术
与IT技术爱好者一起共同学习进步

Linux对比2个文件不同内容之diff命令

案例1:

先建立两个文件diff1.txt和diff2.txt:
linux使用diff命令

[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

再建立两个文件

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. |

linux使用命令行对比文本

表示右比左多,<表示左比右多。|表示不同。

赞(0)
未经允许不得转载:Linux入门学习到精通 » Linux对比2个文件不同内容之diff命令
分享到: 更多 (0)

学习QQ群:557371664

关注微信公众号自助视频学习

评论 抢沙发

评论前必须登录!