Awk would be my first thought, because you have records (newline-separated) with fields (space-separated), and handling that is its specialty.