Compare automatically generated files

During working on https://github.com/dervan/avro-fastserde I had to compare automatically generated code files. I had to directories with files generated by new and old version. Some of the files were generated more than one time, but with the same content. There was also a difference in random numbers, which were added on end of variables name. It’s pretty simple, but I like my one-liner, so I would love to save it here.

Building blocks are:

a) to find java files, each name just once: 

find ./old/ -name "*.java" -printf "%f\n" | sort | uniq

b) regex to change a random number to string “ID”:

%s/\([a-z]\)[0-9]\+/\1ID/ge

c) vim flag to quietly run a command in all windows after files loading:

 vim -c ':windo silent command' files

d) find a flag to quit after first finding:

 find ./old -name "$file" -print -quit`

And together:

for file in `find ./old/ -name "*.java" -printf "%f\n" | sort | uniq`; do vimdiff +':windo silent %s/\([a-z]\)[0-9]\+/\1ID/ge' +':diffupdate' `find ./old/ -name "$file" -print -quit` `find ./new/ -name "$file" -print -quit`; done;

Well, and problem solved in only 210 chars 🙂