There’s an add-on for this:
Or this:
https://www.reddit.com/r/blender/comments/gf2za0/help_replace_multiple_objects_with_another_one/