Question: I am currently working on a source code generation tool. To make sure that my changes do no introduce any new bugs, a `diff` between the output of the program before and after my changes would theoretically be a valuable tool.

However, this turns out to be harder than one might think, because the tool outputs lines where the order does not matter (like `import` statements, function declarations, …) in a semi-randomly ordered way. Because of this, the output of `diff` is cluttered with many changes that are in fact only lines moved to another position in the same file.

Is there a way to make diff ignore these moves and only output the lines that have really been added or removed?

Answer: 
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](http://tldp.org/LDP/abs/html/process-sub.html)

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

```
It sounds like you have control over the tool. Then make its output predictable: instead of emitting declarations in a semi-random order, use (say) alphabetical order as a last resort. This will not only have the benefit of removing useless cruft from diffs, but also of making the tool's output easier to read and verify for a human being.