Input:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
SRT3 STATUSFL1303404GH6 #T# 1
31055ABC0121X6AL5S3 D0 3012052512X226111290N 6AB6922521420 3A
33111XYZ1231Y6AH5S3 D1 3012070312Y2282 N 6AB6922521420 3A
MUT4 STATUSFL1400048MK3 #T# 1
74620DEF2134G1J86CC E1 3012090572Z313372650N 1JC4822521243 4J
74620ZEB3218G1J86CC E2 3012090572O313372650N 1JD4822521243 4J
SRT3 STATUSFL1303404GH6 #T# 1
31055ABC0121X6AL5S3 D0 3012052512X226111290N 6AB6922521420 3A
33111XYZ1231Y6AH5S3 D1 3012070312Y2282 N 6AB6922521420 3A
MUT4 STATUSFL1400048MK3 #T# 1
74620DEF2134G1J86CC E1 3012090572Z313372650N 1JC4822521243 4J
74620ZEB3218G1J86CC E2 3012090572O313372650N 1JD4822521243 4J
Rules:
The header record should copy content from 10th column (15 bytes) and put it before value appearing in 1st column and newly formed value should begin at 13th column and 37th column.
The detail record should add a key field from -
'D' or 'E' appearing at 21st column should be converted to '13' or '14' respectively and copied to 1st column
A Value appearing at 37th column should be copied to 3rd column and 11th column
6 characters starting at 6th column should be copied to 5th column
The 10 characters (STATUSFL13 or STATUSFL14 from respective headers) appearing in header record should be copied to 13th column
The 6 digit value appearing at 23rd column should be copied to 23rd column from respective header record
Output:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
STATUSFL1303404SRT5 STATUSFL1303404GH6
1312ABC01212STATUSFL130340431055ABC0121X6AL5S3 D0 3012052512X226111290N 6
1312XYZ12312STATUSFL130340433111XYZ1231Y6AH5S3 D1 3012070312Y2282 N 6
STATUSFL1400048MUT4 STATUSFL1400048MK3
1472DEF21372STATUSFL140004874620DEF2134G1J86CC E1 3012090572Z313372650N 1
1472ZEB32172STATUSFL140004874620ZEB3218G1J86CC E2 3012090572O313372650N 1
STATUSFL1303404SRT5 STATUSFL1303404GH6
1312ABC01212STATUSFL130340431055ABC0121X6AL5S3 D0 3012052512X226111290N 6
1312XYZ12312STATUSFL130340433111XYZ1231Y6AH5S3 D1 3012070312Y2282 N 6
STATUSFL1400048MUT4 STATUSFL1400048MK3
1472DEF21372STATUSFL140004874620DEF2134G1J86CC E1 3012090572Z313372650N 1
1472ZEB32172STATUSFL140004874620ZEB3218G1J86CC E2 3012090572O313372650N 1
Please help me to achieve this.
Thanks.