Swapping textures / shader of two gameobjects

Hi, I just would like know how could I swap the shader / textures of two gameobjects in order to simulate transparencies. I will explain it better. Imagine that I have 3 elements at different distances: 1) a vertical plane in the background, where I apply a texture based on a picture. 2) An intermediate object with whatever texture (e.g. a red cylinder). 3) A closer irregular surface or terrain.
Now imagine that from a certain position the closer irregular terrain hides partially both objects behind (1: the background plane and 2: the red cylinder).
What I would like to do is to apply a texture or shader to the irregular surface with the pixels of the background plane that it is hiding, in such a way that apparently the surface is invisible but the red cylinder is also invisible in those parts where it is hidden by the surface. Did I explain myself? Thank you very much for your help.

I will reply myself:
Follow the instructions provided by this post and you will find the right way to do it: