简体   繁体   English

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

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

I have the following command: 我有以下命令:

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

It works great; 效果很好; it outputs a list of differences per line to a text file, and then removes every instance of '-' against each line, however I really want to understand what -u is doing and what the following means: 它将每行差异列表输出到文本文件,然后针对每一行删除'-'的每个实例,但是我真的很想了解-u在做什么以及以下含义:

Output NUM (default 2) lines of unified context

Am I right in thinking unified refers to only displaying the differences rather than the context of the differences? 我认为统一是指仅显示差异而不是差异的上下文吗?

Also are there any potential gotchas I should be concerned about with regard to my requirement of displaying differences between two files to another file using the above command? 在使用上述命令显示两个文件与另一个文件之间的差异方面,我是否应该担心任何潜在的陷阱?

This stands for the amount of "context lines" around each diff it finds. 这代表它找到的每个差异周围的“上下文行”数量。

Probably best demonstrated with an example: 最好用一个例子来说明:

$ 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