When you want to do text manipulation, you can use Sed and Awk. These 2 tools which come on most Linux distributions, will allow you to modify text files in many ways.