Yes, I sort of understand what you mean. I guess the only way out to relieve from the bad feeling is to be grateful for what life has brought to us. But I know, feeling is feeling, feeling is not logic. Try it, you may feel different, because our daily life is impacted by our emotional energy on a large scale.
Another angle to see the loneliness is from a long historic point of view. We are all lonely on the way to be born. See the story here: http://www.galactanet.com/oneoff/theegg_mod.html by Andy Weir. So try to forget about it or ignore the feeling and find every piece of joy in your daily life.
I think you are right. When I think on my wife, the loneliness goes away, but it's tempting to fall back into old thinking patterns and habits, no? Sometimes bad feelings you've carried around for a long time are comfortable, like an old pair of shoes.