Code:
#!/usr/bin/ksh
#CONTACT
gzcat *CONTACT* | awk '
{
KEY=substr($0,1,12)
fkey=substr($0,14,12)
addkey=substr($0,27,12)
fkeyEATED=substr($0,40,10)
fkeyEATET=substr($0,51,8)
lkey=substr($0,60,10)
utlkey=substr($0,71,8)
st=substr($0,80,20)
ft=substr($0,101,100)
ft__=substr($0,202,100)
nic=substr($0,303,20)
SUBSfkeyIBERNUMBER=substr($0,324,20)
sco=substr($0,345,20)
stblk=substr($0,366,10)
stblkT=substr($0,377,8)
edb=substr($0,386,10)
edbT=substr($0,397,8)
bckrs=substr($0,406,10)
pckcd=substr($0,417,40)
dlcd=substr($0,458,10)
ppmd=substr($0,469,20)
cstmrd=substr($0,490,20)
dsnnrsn=substr($0,511,20)
sx=substr($0,532,10)
prpd=substr($0,543,1)
ml=substr($0,545,128)
ms=substr($0,674,15)
KEY=trim(KEY)
fkey=trim(fkey)
addkey=trim(addkey)
fkeyEATED=trim(fkeyEATED)
fkeyEATET=trim(fkeyEATET)
lkey=trim(lkey)
utlkey=trim(utlkey)
st=trim(st)
ft=trim(ft)
ft__=trim(ft__)
nic=trim(nic)
SUBSfkeyIBERNUMBER=trim(SUBSfkeyIBERNUMBER)
sco=trim(sco)
stblk=trim(stblk)
stblkT=trim(stblkT)
edb=trim(edb)
edbT=trim(edbT)
bckrs=trim(bckrs)
pckcd=trim(pckcd)
dlcd=trim(dlcd)
ppmd=trim(ppmd)
cstmrd=trim(cstmrd)
dsnnrsn=trim(dsnnrsn)
sx=trim(sx)
prpd=trim(prpd)
ml=trim(ml)
ms=trim(ms)
print SUBSfkeyIBERNUMBER,",1,"KEY,","fkey,","addkey,","fkeyEATED,","fkeyEATET,","lkey,","utlkey,","st,","ft,","ft__,","nic,","SUBSfkeyIBERNUMBER,","sco,","stblk,","stblkT,","edb,","edbT,","bckrs,","pckcd,","dlcd,","ppmd,","cstmrd,","dsnnrsn,","sx,","prpd,","ml,","ms}
function ltrim(s) { sub(/^ +/, "", s); return s }
function rtrim(s) { sub(/ +$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }
'> final
sort final > final2
rm final
gzip final2
mv final2.gz ${data}-fkeym_all.gz