10

I used diff --from-file to compare my Riak dev1 config to the three others.

diff --from-file ~/riak/dev/dev1/etc/app.config \
~/riak/dev/dev2/etc/app.config \
~/riak/dev/dev3/etc/app.config \
~/riak/dev/dev4/etc/app.config

It shows the configs differ only in the port number setting (8091, 8092, 8093, 8094).

It's hard to tell where one file ends and the next begins because the output doesn't contain file names.

11c11
<               {http, [ {"127.0.0.1", 8091 } ]},
---
>               {http, [ {"127.0.0.1", 8092 } ]},
15c15
<               %{https, [{ "127.0.0.1", 8091 }]},
---
>               %{https, [{ "127.0.0.1", 8092 }]},
26c26
<               {handoff_port, 8101 },
---
>               {handoff_port, 8102 },
54c54
<             {pb_port, 8081 },
---
>             {pb_port, 8082 },
11c11
<               {http, [ {"127.0.0.1", 8091 } ]},
---
>               {http, [ {"127.0.0.1", 8093 } ]},
15c15
<               %{https, [{ "127.0.0.1", 8091 }]},
---
>               %{https, [{ "127.0.0.1", 8093 }]},
26c26
<               {handoff_port, 8101 },
---
>               {handoff_port, 8103 },
54c54
<             {pb_port, 8081 },
---
>             {pb_port, 8083 },
11c11
<               {http, [ {"127.0.0.1", 8091 } ]},
---
>               {http, [ {"127.0.0.1", 8094 } ]},
15c15
<               %{https, [{ "127.0.0.1", 8091 }]},
---
>               %{https, [{ "127.0.0.1", 8094 }]},
26c26
<               {handoff_port, 8101 },
---
>               {handoff_port, 8104 },
54c54
<             {pb_port, 8081 },
---
>             {pb_port, 8084 },

Before each "11c11" line, I'd like to see the names of the two files being comared.

git diff can produce output like this:

--- a/home/sandport/riak/dev/dev1/etc/app.config
+++ b/home/sandport/riak/dev/dev2/etc/app.config

How would you do it with standard diff?

2 Answers 2

7

Add the parameter --unified=0 to show the names of each file.

The --unified part sets the output format to 'unified'. The unified format starts with the names of the files being compared.

The =0 part hides the context lines. It makes the output easier to inspect visually.

Rerun the original command with the new parameter and the output will look like this:

--- /home/sandport/riak/dev/dev1/etc/app.config 2013-12-11 02:40:09.000000000 +0000
+++ /home/sandport/riak/dev/dev2/etc/app.config 2013-12-11 02:40:09.000000000 +0000
@@ -11 +11 @@
-              {http, [ {"127.0.0.1", 8091 } ]},
+              {http, [ {"127.0.0.1", 8092 } ]},
@@ -15 +15 @@
-              %{https, [{ "127.0.0.1", 8091 }]},
+              %{https, [{ "127.0.0.1", 8092 }]},
@@ -26 +26 @@
-              {handoff_port, 8101 },
+              {handoff_port, 8102 },
@@ -54 +54 @@
-            {pb_port, 8081 },
+            {pb_port, 8082 },
--- /home/sandport/riak/dev/dev1/etc/app.config 2013-12-11 02:40:09.000000000 +0000
+++ /home/sandport/riak/dev/dev3/etc/app.config 2013-12-11 02:40:09.000000000 +0000
[...]
2

AFAIR git diff uses the patch-file-like output:

diff -Naur old new

Depending on the settings in man diff, you might just need to add the -u flag to your diff statement

1
  • Thanks for the hint, mulaz. 'unified format' was the magic word I had to learn. I added an example in my answer. Commented Dec 28, 2013 at 13:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .