#!/bin/bash

OLDIFS=$IFS
IFS=","

while read team st1 rn1 st2 rn2 st3 rn3
do
    echo "$team,$st1,$rn1" >> output_temp
    echo "$team,$st2,$rn2" >> output_temp
    echo "$team,$st3,$rn3" >> output_temp
done < $1

LC_COLLATE=C sort output_temp >> output
rm output_temp

IFS=$OLDIFS