Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File:

abcdefghijklmnop01qrstuvwxyz
abcdefghijklmnop02qrstuvwxyz
abcdefghijklmnop03qrstuvwxyz
abcdefghijklmnop04qrstuvwxyz
abcdefghijklmnop05qrstuvwxyz

Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number value it shows

Output File:

01abcdefghijklmnop01qrstuvwxyz
a02bcdefghijklmnop02qrstuvwxyz
ab03cdefghijklmnop03qrstuvwxyz
abc04defghijklmnop03qrstuvwxyz
abcd05efghijklmnop05qrstuvwxyz
awk '
        {
                pat1=(substr($0,17,2))
                sub(pat1,"")
                pat2=substr($0,0,NR-1)
                sub(pat2,"")
                print pat2 pat1 $0
        }
' infile

Output:

01abcdefghijklmnopqrstuvwxyz
a02bcdefghijklmnopqrstuvwxyz
ab03cdefghijklmnopqrstuvwxyz
abc04defghijklmnopqrstuvwxyz
abcd05efghijklmnopqrstuvwxyz

Something like this?

awk '{$0=substr($0,1,i++) substr($0,17,2) substr($0,i)}1' file

Thanks!!! worked like magic

bash

while read -r line
do
    num=${line:16:2}
    echo "${line:0:$num-1}${num}${line:$num}"
done < "file"

perl -ne '{s/(.*[^0-9]*)([0-9]+)([^0-9].*)/substr($1,0,$2-1).sprintf("%02d",$2).substr($1,$2-1).$2.$3/e;print;}'

The OP asked:

So imo only ghostdog and summer cherry's solutions are working correctly. I prefer Ghostdog's solution because it is nice and simple.