Code:
awk -F: '
NR==1 {HD = "insert_job,machine,date_conditions,days_of_week,start_time,timezone,description,command,alarm_if_fail"
for (HDCnt=i=split(HD, HDArr, OFS); i>0; i--) SRCH[HDArr[i]]
print HD
}
function PRT() {for (i=1; i<=HDCnt; i++) {printf "%s%s", RES[HDArr[i]], i<HDCnt?OFS:ORS
}
split ("", RES)
}
/--- JOB/ {if (PR) PRT()
PR=1
}
$1 in SRCH {T = $1
sub ($1 FS " *", "")
sub (/ +.*$/, "")
RES[T] = $0
}
END {PRT()
}
' OFS="," file
insert_job,machine,date_conditions,days_of_week,start_time,timezone,description,command,alarm_if_fail
JOB1,,1,mo,tu,we,th,fr,su,"18:30",US/Eastern,"pull files",,1
JOB2,machine@conti.com,,sa,su,,GMT,"pull all files",/usr/bin/run /usr/cache/START_JOB,1