Perhaps write a small bash/awk script to do the job?