How to write a condolence letter?
It all depends on how well you know the person you're writing to, and how well you knew the deceased. I think an important point is not just to write that you're sorry, but to add some personal words - preferably a recollection or pleasant anecdote about the deceased, that the letter-reader will be able to think of and maybe get some consolation.
Just tell them how you really feel. Tell them you are very sorry for what happened to their family. There is no universal format for condolence letter.