You posted expected output doesn't really make sense (e.g. 2 commas for one apparent field at 0, , and sometimes you have blanks before the comma, sometimes after it, and sometimes before AND after it) and I think your sample input isn't accurate (e.g. 215 and 0.2% appears too close together) so I'm guessing but - using GNU awk for FIEDWIDTHS and nextfile, this may be what you really want to do:
$ cat tst.awk
NR == FNR {
if ( /^[- ]+$/ ) {
wids = length($1)
for ( i=2; i<=NF; i++ ) {
wids = wids " " length(FS $i)
}
nf = NF
nextfile
}
next
}
FNR == 1 {
FIELDWIDTHS = wids
OFS = ","
$0 = $0
}
NF { $nf = $nf }
{ print }
$ awk -f tst.awk file file
ID , Status , Error Code, Start Time , Elapsed , End Time , Type , Progress Bytes , New Bytes
----------------, ------------------------, ----------, --------------------, -----------, --------------------, ----------------, -----------------, ---------
9133910640004809, Completed w/Exception(s), 10020 , 2012-06-07 18:00 EDT, 00h:53m:46s, 2012-06-07 18:53 EDT, Scheduled Backup, 215 0.2%,
9133914600006909, Completed , 0 , 2012-06-08 05:00 EDT, 00h:00m:04s, 2012-06-08 05:00 EDT, Scheduled Backup, 0 , 0%
or:
$ cat tst.awk
NR == FNR {
if ( /^[- ]+$/ ) {
wids = length($1)
for ( i=2; i<=NF; i++ ) {
wids = wids " " length(FS $i)
}
nf = NF
nextfile
}
next
}
FNR == 1 {
FIELDWIDTHS = wids
OFS = ","
$0 = $0
}
NF {
$nf = $nf
$0 = gensub(/( +),/,",\\1","g")
}
{ print }
$ awk -f tst.awk file file
ID, Status, Error Code, Start Time, Elapsed, End Time, Type, Progress Bytes, New Bytes
----------------, ------------------------, ----------, --------------------, -----------, --------------------, ----------------, -----------------, ---------
9133910640004809, Completed w/Exception(s), 10020, 2012-06-07 18:00 EDT, 00h:53m:46s, 2012-06-07 18:53 EDT, Scheduled Backup, 215 0.2%,
9133914600006909, Completed, 0, 2012-06-08 05:00 EDT, 00h:00m:04s, 2012-06-08 05:00 EDT, Scheduled Backup, 0, 0%