awk -F, 'NR==1{c=$1+1}$1!=c{printf "%s ",$0}$1==c{c++;printf "\n%s",$0}END{printf ORS}' file1 > file2