BEGIN{ FS="_" OFS="," print "ID,group1,group2,group3" } FNR>1{ val=$0 $1=$1 print val,$0 }