You can keep your messages brief, especially if you do not know the person well.
Do not infer that you know how the person is feeling. Many people react to loss in different ways and grieve at different rates.
Use humor very wisely. Only use humor if you know that it will be helpful. Save the jokes for happy occasions.
Feeling awkward around the person who has suffered a loss is common, but being willing to listen and hang out with the person will make you both feel better. A nicely written sympathy message is a great way to break the ice without having to say the right things perfectly on the spot.
Describe you own sad feelings, but be careful not to tell the grieving person how they feel.
Express something positive about the person who died, even if you heard some negative things about him or her at times.
Offer your support by offering to help with something specific. “I will call you on Tuesday” is much better than “I am here for you” which is much more general.