What’s the diff?

My problem was that my revised version of the Java program did not work as expected. While I believed that I had changed nothing but comments, the results were not the same. What had I changed?

“Oh, that’s easy” says I, “I’ll just diff the files and see what changed”. Well according to diff, EVERYTHING had changed. I used the regular options like -w, and -E, and -d, and -B and still no improvement.

“Duh”, he says, “it’s the encoding”. What is the diff option to compare two texts with different encoding? The short answer seems to be that there is no option.

But where there’s a will, there’s a way, particularly with Linux (and Unix). In Linux use the iconv command to do the conversion and pipe the output to diff for the compare.

If you do not know iconv, the short form is:

iconv -f from-file-encoding -t to-file-encoding from-file-name

Output to stdout.

Pipe it to diff and tell diff to pick up the input from the pipe with a dash – .

If you do not know the encoding of the files, use the file command to show you the encoding.

To find out if the encoding is supported (and spelled correctly), use

iconv -l

for a list of supported encodings.

The answer to the original question looks like:

iconv -f ISO-8859-1 -t UTF-8 ../x3-2.14/x3navaldv0.2.14/java/bateau/Bateau.java | diff -w - java/bateau/Bateau.java

I had changed only comments. Compiler difference? Compiler option difference?

One Reply to “What’s the diff?”

  1. The answer is that the internal constants used to compare the fields stored in the text data files as samples no longer matched the text strings in the program. New files created with the new program work as expected.

Leave a Reply