assuming this: 01E000036841 is an employee id and the files are named <something>.dat
Code:
ls *.dat | read header dummy
# save copies of header
head -1 $header > tmp
awk '{ if (index($0, "HEADER") > 0 || index($0, "TRAILER") >0 ) {last= $0; continue}
arr[$0]++; print $0 }
END { for (i in arr)
{
empcnt++
lc+=arr[i]
}
print empcnt, lc > "cntfile" } ' *.dat >> tmp
awk ' { rec=sprintf("%08d%08d", $1 $2)}
END { printf("BATCH TRAILER %s%s\n", rec, substr(last, length(last)-7) } ' cntfile >> tmp
mv tmp employee.dat
This also assumes the last eight characters of BATCH TRAILER are all the same.