converting text to csv format

I am trying to check each line and based on first two digits, the comma needs to be place. I checked in the earlier post where the text is converted to csv with a tab delimited.
Here is the test file that needs to be changed to csv

11 051701
22 051701
330123405170105170112345
0100001123456789012987654321
0100002123456789012987654321
0100003123456789012987654321
0100004123456789012987654321
0100017123456789012987654321
.......

if the first 2 digits are 11, then a comma is placed after 2nd column and just before the 051701. If the first two digits are 01 then the commas should be place after 01, another comma after 00001, another after 123456789012. In short the output should look like this

11, ,051701
22, ,051701
33,01234,051701,051701,12345
01,00001,123456789012,987654321
01,00002,123456789012,987654321
01,00003,123456789012,987654321
01,00004,123456789012,987654321
01,00017,123456789012,987654321
.......

Any help is appreciated. Thanks
~

here's something to start with:

nawk -f gt.awk myFile.txt

gt.awk:

/^11/ && NF == 2 { $1=$1 "," ;$2="," $2; print; next }
/^01/ {
   $0 = substr($0,1,2) "," substr($0,3,5) "," substr($0,8,12) "," substr($0, 13)
   print
}

Thanks a lot. I was able to modify accordingly with my text file and was able to get the desired csv format file. Appreciate and thank you for your quick response.

I was able to get the csv file without any problem. I have one quick question. Is it possible to take the 2nd column on line 3, '01234' and have it on each and every line where you see '01' as the first two characters, like for example

11, ,051701
22, ,051701
33,01234,051701,051701,12345
01,00001,123456789012,987654321
01,00002,123456789012,987654321
01,00003,123456789012,987654321
01,00004,123456789012,987654321
01,00017,123456789012,987654321
.......

to

11, ,051701
22, ,051701
33,01234,051701,051701,12345
01234,01,00001,123456789012,987654321
01234,01,00002,123456789012,987654321
01234,01,00003,123456789012,987654321
01234,01,00004,123456789012,987654321
01234,01,00017,123456789012,987654321
.......

this one,

sed -n /^01/p filename | sed "s/^01/`awk -F"," '{ if(NR==3) { print $2 } }' filename`/g"

[not tested]
nawk -f gt.awk filename

gt.awk:

BEGIN {
   FS=OFS=","
}
FNR==3 { num=$2 }
FNR != 3 && $1 == "01" { $1 = num OFS $1 }
1

Thanks for your reply. Actually the suggestion you gave is replacing the value from '01' to '01234' and eliminating the other rows. Is there any way to keep the other rows as is and concatenate the '01234' from '33' line to '01' lines. This should be included in the code that was suggested earlier by vgersh99 in gt.awk

[not tested]

BEGIN {
   FS=OFS=","
}
FNR==3 { num=$2 }
FNR != 3 && $1 ~ /^01/ { $1 = num OFS $1 }
/^11/ && NF == 2 { $1=$1 OFS ;$2="," $2; print; next }
/^01/ {
   $0 = substr($0,1,2) OFS substr($0,3,5) OFS substr($0,8,12) OFS substr($0, 13)
}
1

When running the above code I get the following result.

11, ,051701
22, ,051701
33,01234,051701,051701,12345
01,234,0,1,00001,1234,01,123456789012,987654321
01,234,0,1,00002,1234,02,123456789012,987654321
01,234,0,1,00003,1234,03,123456789012,987654321
01,234,0,1,00004,1234,04,123456789012,987654321
01,234,0,1,00017,1234,17,123456789012,987654321

where as I am looking for something like

11, ,051701
22, ,051701
33,01234,051701,051701,12345
01234,01,00001,123456789012,987654321
01234,01,00002,123456789012,987654321
01234,01,00003,123456789012,987654321
01234,01,00004,123456789012,987654321
01234,01,00017,123456789012,987654321

FYI

BEGIN {
   FS=OFS=","
}
FNR==3 { num=$2 }
/^11/ && NF == 2 { $1=$1 OFS ;$2="," $2; print; next }
/^01/ {
   $0 = substr($0,1,2) OFS substr($0,3,5) OFS substr($0,8,12) OFS substr($0, 13)
}
FNR != 3 && $1 ~ /^01/ { $1 = num OFS $1 }
1

here is the shot !!!

awk -F"," '{ if( NR == 3 ) { val=$2;print }  if( NR < 3 ) { print } else {print val","$0} }' filename

o/p:

11, ,051701
22, ,051701
33,01234,051701,051701,12345
01234,33,01234,051701,051701,12345
01234,01,00001,123456789012,987654321
01234,01,00002,123456789012,987654321
01234,01,00003,123456789012,987654321
01234,01,00004,123456789012,987654321
01234,01,00017,123456789012,987654321

the above would serve ur purpose

Line 4 is a repeat of line 3 with '01234' concatenated.

you got it !!!

that was a simple encounter,

awk -F"," '{ if( NR == 3 ) { val=$2 }  if( NR <= 3 ) { print } else {print val","$0} }' filename

o/p

11, ,051701
22, ,051701
33,01234,051701,051701,12345
01234,01,00001,123456789012,987654321
01234,01,00002,123456789012,987654321
01234,01,00003,123456789012,987654321
01234,01,00004,123456789012,987654321
01234,01,00017,123456789012,987654321

Thanks a lot for all your help.