group messages by line, format message