txt1文件的內容

aaa bbb ccc
111 222
333

txt2文件的內容

aaa bbb ccc
155 228
393
jjj

比較一下 txt1與txt2的不同

diff txt1 txt2
# txt1的二、三行換成txt2的二、三、四行
2,3c2,4
< 111 222
< 333

> 155 228
> 393
> jjj

製作 patch 檔案

diff -Nur txt1 txt2 > txt3
— txt1        2007-08-16 22:43:49.000000000 +0800
+++ txt2        2007-08-16 22:44:13.000000000 +0800
@@ -1,3 +1,4 @@
 aaa bbb ccc
-111 222
-333
+155 228
+393
+jjj

參數解釋:

-a     Treat all files as text and compare them line-by-line, even if they do not seem to be text.

-N
       –new-file
              In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory.

       –new-group-format=format
              Use format to output a group of lines taken from just the second file in if-then-else format.

       –new-line-format=format
              Use format to output a line taken from just the second file in if-then-else format.

       –old-group-format=format
              Use format to output a group of lines taken from just the first file in if-then-else format.

       –old-line-format=format
              Use format to output a line taken from just the first file in if-then-else format.

-r     When comparing directories, recursively compare any subdirectories found.

-u     Use the unified output format.

更新 patch 至 txt1

patch -p0 < txt3

參數解釋

-p0 : 完整路徑 /root/tmp/xxx.txt

-p1 : tmp/xxx.txt

-p2 : xxx.txt

ref: http://140.111.152.155/blog/post/2/116

ref: http://www.reality.hk/articles/2004/08/31/268/
ref: http://www.ibm.com/developerworks/cn/linux/l-diffp/index.html

最後修改日期: 2007 年 08 月 16 日

作者

留言

撰寫回覆或留言

發佈留言必須填寫的電子郵件地址不會公開。