繁体   English   中英

输出NUM(默认2条)统一上下文行-这是什么意思?

[英]Output NUM (default 2) lines of unified context - what does it mean?

我有以下命令:

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

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

Output NUM (default 2) lines of unified context

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

在使用上述命令显示两个文件与另一个文件之间的差异方面,我是否应该担心任何潜在的陷阱?

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

最好用一个例子来说明:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM