When one sees a person afflicted with any difficulty or calamity, then he should recite the following dua. Through reciting this dua, he will be saved from such a difficulty or calamity. However, one should refrain from reciting the dua aloud before the person afflicted as this may cause him grief and pain.
All praise is due to Allah, Who has saved me from that (difficulty or calamity) which He has brought upon you, and He has granted me virtue over many of His creation.
عن أبي هريرة، قال: قال رسول الله صلى الله عليه وسلم: من رأى مبتلى، فقال: الحمد لله الذي عافاني مما ابتلاك به، وفضلني على كثير ممن خلق تفضيلا، لم يصبه ذلك البلاء. (سنن الترمذي، الرقم: 3432)
Hazrat Abu Hurairah (radhiyallahu ‘anhu) reports that Rasulullah (sallallahu ‘alaihi wasallam) said, “Whoever sees a person afflicted with any difficulty or calamity and recites the following dua, (insha Allah) that difficulty or calamity will not befall him.”