Salesforce – How to automatically clean up profiles and permission sets?

I recently had a problem – I needed to

  1. retrieve profiles and permission sets from Salesforce dev org
  2. clean them up to prepare for deployment

Although retrieving is easy, manual cleaning takes some time. Especially when you have to do the same from time to time.

This might happen if we have different API version between orgs, or a
managed package installed in source org and not in destination org.