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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.