If one has bought shares in a company not knowing it is haram or not shariah compliant, he has to sell whatever he owns of shares in that company, but he does not have to purify anything; if selling it will cause a loss, then he may wait until he can regain his capital.
Fatwa link for the same is as below.