Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 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

share|improve this answer
    
Thanks for the hint, mulaz. 'unified format' was the magic word I had to learn. I added an example in my answer. –  Iain Elder Dec 28 '13 at 13:24

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
[...]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.