Data file is fixed length file, and I want to read the file record by record and do transformations to the subsequent records based on the prior records (and write the results into another file).
Example:
CTD1234abcdTRN0001
AA 5678defg
BB 8910erty
CTD5678qwerTRN5678
AA 9876bvcn
BB 8765zxcv
Now I want TRN0001
from the CTD
record to be written to the subsequent AA
and BB
records, similarly for the following CTD
records. My output should look like:
CTD1234abcdTRN0001
AA 5678defgTRN0001
BB 8910ertyTRN0001
CTD5678qwerTRN5678
AA 9876bvcnTRN5678
BB 8765zxcvTRN5678
Example 2:
AAABBBB11115678xxxx
BBBCCCC22221234YYYY
MTD0001abcdTRN12345 abcdedfg
AA 0002bcde
BB 0003defg
CCCDDDD33331234zzzz
MTD0003qwerTRN56789 defghigk
AA 9876bvcn
BB 8765zxcv
XXXBBBB11115678aaaa
YYYCCCC22221234bbbb
should become
AAABBBB11115678xxxx
BBBCCCC22221234YYYY
MTD0001abcdTRN12345 abcdedfg
AA 0002bcdeTRN12345
BB 0003defgTRN12345
CCCDDDD33331234zzzz
MTD0003qwerTRN56789 defghigk
AA 9876bvcnTRN56789
BB 8765zxcvTRN56789
XXXBBBB11115678aaaa
YYYCCCC22221234bbbb
Can you please help me on this, how can you achieve this using UNIX shell scripting?