Here is a great podcast from Invisibilia.  It talks about various ways to think about and handle unwanted thoughts.  You might be surprised about how common some of your “bad” thoughts are.  It also includes a segment on exposure and response prevention therapy.

The Secret History of Thoughts