How to ignore moved lines in a diff

You could do a simple diff, store the result somewhere (to avoid another diff), loop through the lines in either version, then remove those from the other side.

This spawned a separate project for the working code. The code.


You may try to sort'em first. Something like:

sort file-a > s-file-a
sort file-b > s-file-b
diff s-file-a s-file-b

Bash (and zsh) can do this in one line with process substitution

diff <(sort file-a) <(sort file-b)

If the file is structured into sections, it is just the sections that are out of order, and there exists a regular expression that you can use to recognize the section header, you could csplit the files into their sections and then compare the sections pairwise.

For instance, I just did this on two MySQL dumps to compare them after some of the database names had changed case (and therefore the dump listed them in a different order):

csplit all-07sep2015-11:19:12.sql '/Current Database/-1' '{*}'  # split the dump made before the change, creating files xx00, xx01, ...
csplit -f yy all-07sep2015-12:26:12.sql '/Current Database/-1' '{*}' # split the dump made after the change, creating files yy00, yy01, ...
fgrep 'Current Database' xx?? yy?? | perl -lne 'BEGIN{my %foo}; /(^....).*`(.*)`/ and push(@{$foo{lc($2)}}, $1); END {printf("diff -di %s %s\n", @{$_}) for values %foo}' | sh -x | less  # match the pairs and compare them with diff