There are three main reasons that negative thoughts and patterns repeat themselves even though something within us recognises them as such and feels the need to get rid of them.
The single most important reason is grooves of habit imprinted upon the subconscient and the physical mind. The way to get rid of it is to witness them when they arise without rushing into the impulse to act or adding an emotional force to them. The second method is Japa, a repetition of the Divine Name. Of course, Japa has many other aspects besides but it is one of the most powerful means to act upon the body, the physical mind and the subconscient parts. But one has to persist since subconscient habits take time to get removed.
Preoccupation with the bodily self and the outer life tends to drag us into zones of consciousness where negative energies freely circulate and draw us into a small and narrow whirlpool of thought and feelings. This can be dealt with by turning our mind inwards and upwards through concentration or reading of books that are filled with uplifting thought energies such as the works of Swami Vivekananda and Sri Aurobindo and the Mother.
A third and often overlooked reason is the atmosphere of people with whom we closely relate or the places we work or the people we live with. This may strongly depend on a professional occupation – for example, a doctor may be unwittingly absorbing some pain and suffering and fears of patients. The way here is to practice inner detachment and equanimity.
One simple way is to of course to turn the mind away from these thoughts and divert it through some book or activity. Another everyday practical way that works is taking a bath with some salt.