Check Character matching from pos 7-15 to pos 211-219 if True then replace 211-219 with spaces

Script for if characters from positions 7-15 are matching with characters from position 211-219 then replace all char from 211-219 with 9 space.
Total length of record is 420. Here is the specification of the data in file.

Position    Field Data Type
-----------------------------------------------------
1          Capital Letter total length = 1
2-6          Blanks
7-15         Numeric Data total length 9
16-19       Numeric Data total length 4
20-25       Year and Month.
26-31        Blanks
32           Character Data total length 1
33           Character Data total length 1
34-41        Blanks
42-43        Character Data total length 2
44-48        Blanks
49          Capital Letter total length = 1
50-89          Character total 39 length
90-129        Character total 39 length 
130          Capital Letter total length = 1
131-170          Character Data total length 39
171-199         Alphabetic Data total length 29
200-201         Character Data total length 2
202-210         Numeric Data total length 5
211-219         Numeric Data total length 9
220-290         Character Data total length 60
291-330          Character Data total length 39
331-359       Alphabetic total length 29 character 
360-361       Character Data total length 2
362-370       Numeric Data total length 5
371           Capital Letter total length = 1
372-420         Blanks

Any help on this will be appreciated. Thanks in advance.

Please use code tags when showing input and output strings. You say that the total record length of each of your input and output records is 413, but the three input records you have given us contain 152, 143, and 152 bytes, respectively (not counting the terminating <newline> character) and each of your three output records contain 143 bytes.

You also give two conflicting descriptions of what is in the 1st record.

Making a guess at what your input really looks like, the following may work:

awk '{if(length() > 220 && substr($0,7,9) == substr($0,211,9))
                printf("%s         %s\n", substr($0,1,210), substr($0,220))
        else    print}' input

Guys I've updated the code tags with specs for more detailed info.
Thanks for you help. Sorry for the typo and confusion.

see:

Like this (not tested)?

awk 'substr($0,7,9)==substr($0,211,9){
$0=substr($0,1,210) sprintf("%9s",x) substr($0,220)
}1' file
1 Like

Thanks elixir_sinari.
Your code worked fine.
Thanks a lot for your help & time on this.:slight_smile: