eLRuLL
eLRuLL

Reputation: 18799

Compare files content with similar names on two folders

I have two folders (I'll use database names as example):

These two folders have similar files inside like:

Those files have content also very similar, only changing the name of the database for example, so they all have code or configuration only changing the name Mongo for Cassandra.

How can I compare this two folders, so the result is the files missing from one to the other (for example the file CassandraPlugin for the CassandraFolder) and also that the contents of the files alike, have to be similar, only changing the database name.

Upvotes: 1

Views: 527

Answers (2)

user829755
user829755

Reputation: 1598

the following provides a full diff, including missing files and changed content:

cp -r CassandraFolder cmpFolder
# rename files
find cmpFolder -name "Cassandra*" -print | while read file; do
    mongoName=`echo "$file" | sed 's/Cassandra/Mongo/'`
    mv "$file" "$mongoName"
done
# fix content
find cmpFolder -type f -exec perl -pi -e 's/Cassandra/Mongo/g' {} \;

# inspect result
diff -r MongoFolder cmpFolder # or use a gui tool like kdiff3

I haven't tested this though, feel free fix bugs or to ask if something specific is unclear. Instead of mv you can also use rename but that's different on different flavours of linux.

Upvotes: 1

perreal
perreal

Reputation: 98118

This will give you the names of the missing files (minus the database name):

find MongoFolder/ CassandraFolder/ | \
      sed -e s/Mongo//g -e s/Cassandra//g | sort | uniq -u

Output:

Folder/Plugin

Upvotes: 1

Related Questions