diff 命令和patch文件的使用

1. 使用diff命令

现有text1.txt和text2.txt两个文件:
text1.txt

this is the first line
this is the second line
this is the thiid line

text2.txt

this is the first line
this is the second line
this is the third line

两个文件的区别是第三行 third 单词有误。

使用diff命令输出两个文件的区别:

diff text1.txt text2.txt

output:

3c3
< this is thiid line
---
> this is third line

将diff输出保存为patch文件:

diff text1.txt text2.txt > amend.patch

2. patch文件的使用

拿到amend.patch文件后,可以使用patch命令将其作用在text1.txt 或者 text2.txt

amend.patch文件保存的是由text1.txt到text2.txt的修改,所以将amend.patch作用到text1.txt文件上,text1.txt就会变为text2.txt

patch text1.txt amend.patch

这时参看text1.txt:

cat text1.txt

output:

this is first line
this is second line
this is third line

text1.txt的单词错误已经改正,与文件text2.txt文件一致。

amend.patch文件同样可以作用到text2.txt上,不过patch命令会探测到由text2.txt回退到text1.txt,这时需要加上-R参数:

patch -R text2.txt amend.patch
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值