Had you given the resp. info before, when requested to do so, the script had already had the necessary constructs. Try
awk -vPOS=31 -vLEN=3 ' # run awk, pass parameters for suffix position and length
NR == 1 {HD = $0 # save header to be printed in all output files
next # no further action needed on this line
}
{SFX = substr ($0, POS, LEN) # extract suffix from POSition, LENgth characters
if (SFX == "000") next # no further action on trailer line
FN = FILENAME "_" SFX # compose output file name
}
!(FN in CNT) {print HD > FN # print header for new files (FN not yet registered)
}
{print > FN # print to resp. output file
CNT[FN]++ # count hits for file name AND register it
}
END {for (FN in CNT) {print > FN # print trailer record to every single out file
close (FN) # close file (could be dropped)
print "mv " FN " " FN "_" CNT[FN]
# output rename commands to stdout for execution by sh
}
}
' file | sh # pipe stdout to shell for rename operations
Well, I checked csplit but my version didn't have a size nor a chunk count option - you need one of the two plus the regex for the empty line to accomplish what is requested.