I have a source file with two similar yet subtly different sections. I'd like to merge the two sections into one subroutine with a parameter that handles the subtle differences, but I need to be sure I'm aware of them all so I don't miss any.
What I usually do in such cases is copy each of the sections to a separate file and then use tkdiff or vimdiff to highlight the differences. Is there any way to skip the intermediate files and just diff two parts of the same file?
views:
287answers:
6I use Beyond Compare.
It allows you to select a line on each side and say 'Align Manually'. This should work just fine for you.
If you can describe the start and end of the sections to compore with a regex you can use the following:
sh -c 't=`mktemp`; cat "$0" | grep -e "$2" -A10000 | grep -e "$3" -B 10000 > $t; cat "$1" | grep -e "$2" -A10000 | grep -e "$3" -B 10000 | diff -u $t - ; rm $t' firstfile secondfile "section start" "section end"
As an alternative you if you want to describe the section by line number you can do:
sh -c 't=`mktemp`; cat "$0" | head -$3 |tail +$2 > $t; cat "$1" | head -$5 | tail +$4 | diff -u $t - ; rm $t' first second 4 10 2 8
4 10 2 8 is the start and end line number for the section to consider from the first file and the second file.
You can either save the snippets a shell scripts or as aliases.
KDiff3 is open source and available on several platforms including Win32 and Linux.
It has the "manual alignment" feature discussed by Gyshu about Beyond Compare (which by the way I haven't been using personally but is considered a great tool by many people I know).
Any diff tool that lets you manually adjust the alignment will do the job. Diffuse (http://diffuse.sourceforge.net/) is my favourite and it also lets you manually adjust the alignment.