簡體   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