I’ve been working on a fortran codebase with a lot of code duplicated between subroutines, so I came up with this little bash function using awk to extract subroutines, so I can find the difference between them.
The awk in the function dumps the text from a file between the 2 given deliminators to standard output. In this case we look for the begining of the subroutine, then find the ending block of the subroutine.
I would use this to extract 2 similar subroutines to files, and then
compare them using vimdiff
. This allowed me to quickly spot the
similarlarities between them and remove the duplicated code.