Wednesday, October 3, 2012

Compare two files for specific word/s

Problem: We may have defined a set of functions used across project level, and assume that there is need to change/add/delete the functions as we move ahead.

For some reason, if your development and production copy may may not in sync. But you already added or changed the dev copy. Then, you want to make sure that you are missing any function/s that you really need.
In such cases we can use regular diff command - But the problem here is the output of diff may not be that readable. for a beginner like me.

So, here is another way of comparing two files no matter in what order they have the functions/keywords you need to compare.


echo "The function missing in new/modified copy if any"
grep "^search keyword" $PATH/$OLD_FILE_NAME | while read i; do echo %%%%$i%%%%% $(grep "$i" $PATH/NEW_FILE_NAME) ; done | grep "%%$"
echo "The result above usually should be empty"\

echo "Newly added functions are"
grep "^search keyword" $PATH/NEW_FILE_NAME | while read i; do echo %%%%$i%%%%% $(grep "$i" $PATH/$OLD_FILE_NAME) ; done | grep "%%$"

No comments:

Post a Comment