0

我有以下命令:

diff -u filea fileb | grep '^-' | sed 's/^-//' > diff.txt

效果很好;它将每行的差异列表输出到文本文件,然后针对每一行删除“-”的每个实例,但是我真的很想了解 -u 在做什么以及以下含义:

Output NUM (default 2) lines of unified context

我是否认为统一是指仅显示差异而不是差异的上下文?

关于使用上述命令将两个文件之间的差异显示到另一个文件的要求,我是否应该关注任何潜在的问题?

4

1 回答 1

0

这代表它找到的每个差异周围的“上下文行”的数量。

可能最好用一个例子来说明:

$ diff -U 1 hello.txt hello2.txt
--- hello.txt   2015-01-24 16:10:45.000000000 +0100
+++ hello2.txt  2015-01-24 16:11:14.000000000 +0100
@@ -4,3 +4,3 @@
 Hello World.
-Hello World.
+Yo World.
 Hello World.

$ diff -U 2 hello.txt hello2.txt
--- hello.txt   2015-01-24 16:10:45.000000000 +0100
+++ hello2.txt  2015-01-24 16:11:14.000000000 +0100
@@ -3,5 +3,5 @@
 Hello World.
 Hello World.
-Hello World.
+Yo World.
 Hello World.
 Hello World.

$ diff -U 3 hello.txt hello2.txt
--- hello.txt   2015-01-24 16:10:45.000000000 +0100
+++ hello2.txt  2015-01-24 16:11:14.000000000 +0100
@@ -2,7 +2,7 @@
 Hello World.
 Hello World.
 Hello World.
-Hello World.
+Yo World.
 Hello World.
 Hello World.
 Hello World.
于 2015-01-24T15:13:28.347 回答