|
板凳

楼主 |
发表于 2011-6-3 11:51:24
|
只看该作者
Unified Format 统一输出格式
Unified Format 格式是上面 Context Format 输出格式的一个变种,它忽略了一些冗余的内容输出,使能这种输出格式可以使用 -U lines, --unified[=lines], 或 -u 这些选项,其中参数 lines 指示在输出相异的结果后输出几行相同的内容,如果不指定则默认为 3 行,如:
lao tzu 仍然采用上面 context format 中引用的内容。$ diff -U 1 lao tzu
--- lao 2011-06-03 09:20:59.000000000 +0800
+++ tzu 2011-06-03 09:22:00.000000000 +0800
@@ -1,5 +1,4 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
Therefore let there always be non-being,
@@ -11 +10,4 @@
they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!
$ diff -U 2 lao tzu
--- lao 2011-06-03 09:20:59.000000000 +0800
+++ tzu 2011-06-03 09:22:00.000000000 +0800
@@ -1,6 +1,5 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
Therefore let there always be non-being,
so we may see their subtlety,
@@ -10,2 +9,5 @@
But after they are produced,
they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!
$ diff -u lao tzu
--- lao 2011-06-03 09:20:59.000000000 +0800
+++ tzu 2011-06-03 09:22:00.000000000 +0800
@@ -1,7 +1,6 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
Therefore let there always be non-being,
so we may see their subtlety,
And let there always be being,
@@ -9,3 +8,6 @@
The two are the same,
But after they are produced,
they have different names.
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties!
$ diff -U 9 lao tzu
--- lao 2011-06-03 09:20:59.000000000 +0800
+++ tzu 2011-06-03 09:22:00.000000000 +0800
@@ -1,11 +1,13 @@
-The Way that can be told of is not the eternal Way;
-The name that can be named is not the eternal name.
The Nameless is the origin of Heaven and Earth;
-The Named is the mother of all things.
+The named is the mother of all things.
+
Therefore let there always be non-being,
so we may see their subtlety,
And let there always be being,
so we may see their outcome.
The two are the same,
But after they are produced,
they have different names. #这里最多只有 7 行相同的,所以即使指定 9 也只能输出 7 行
+They both may be called deep and profound.
+Deeper and more profound,
+The door of all subtleties! 在上面的输出中:--- lao 2011-06-03 09:20:59.000000000 +0800
+++ tzu 2011-06-03 09:22:00.000000000 +0800 这是输出头,依次为文件名,时间戳,时区。这个头可以用 --label=LABEL 选项进行修改。
@@ -10,2 +9,5 @@ 表示比较的区间。注意比较区间数字前面的加 "+", "-" 符号,这和头部中的 "+", "-" 符号是对应着的,这里 "-" 号代表 lao 这个文件,"+" 号代表 tzu 这个文件。10,2 和 9,5 这种形式为 start,count ,表示从哪行开始比较(start),接着比较多少行(count) 。
在比较结果输出中,前面不带 "-" 和 "+" 号的行表示两个文件中存在相同的行;前面带有 "-" 号的行表示 lao 这个文件中有而 tzu 这个文件中没有或者是 tzu 文件中有异于 lao 文件中的行。"+" 号的意思正好是 "-" 号反过来之意。 |
|