[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Which Diff tool could I use for visually comparing two text files where Word Wrap is possible?



On Sat, Apr 01, 2023 at 01:41:22AM +0000, davidson wrote:
> On Sat, 1 Apr 2023 davidson wrote:
> > Start here instead:
> > 
> > $ diff file1 file2
> > 
> > It displays the differences, and your terminal will wrap lines (and
> > break words) to fit the window for you.
> > 
> > Does it do what you want?
> 
> A concise explanation of diff's default output format (which is a
> little cryptic but quite simple) can be viewed in the info browser
> with
> 
>  $ info -n "Detailed Normal" diffutils # type 'q' to quit
> 
> or written to a text file with
> 
>  $ info -o diff_format_explained.txt -n "Detailed Normal" diffutils

Most people prefer diff -u format.  Here's a quick sample of the three
formats:

unicorn:~$ diff <(seq 1 3) <(printf '1\n4\n3\n')
2c2
< 2
---
> 4


unicorn:~$ diff -c <(seq 1 3) <(printf '1\n4\n3\n')
*** /dev/fd/63	Fri Mar 31 21:53:34 2023
--- /dev/fd/62	Fri Mar 31 21:53:34 2023
***************
*** 1,3 ****
  1
! 2
  3
--- 1,3 ----
  1
! 4
  3


unicorn:~$ diff -u <(seq 1 3) <(printf '1\n4\n3\n')
--- /dev/fd/63	2023-03-31 21:53:37.023781025 -0400
+++ /dev/fd/62	2023-03-31 21:53:37.023781025 -0400
@@ -1,3 +1,3 @@
 1
-2
+4
 3


The first one (default) gives no context lines.  It simply says "replace
line 2, which is "2", with "4".  This works fine for some inputs, but it
doesn't allow for applying a code patch to a function that has moved a
few lines down in the file since the patch was written.

So, the second format, "context", was introduced.  It shows the lines
before and after the change.  This allows the patch applier to look around
in the file and find the appropriate place to apply the patch, if the
content has moved around.

The third format, "unified", is just a more compact version of "context".
It shows the lines before and after the change, but only once instead
of twice.

In some ways, the "context" format can be easier to read, because you
see the actual new content exactly as it should appear, without the
old lines interwoven.

On the other hand, the "unified" format shows you the before and after
lines right next to each other.  In some cases, that can be easier to
use.  Especially once you get used to it.


Reply to: