replacing a quote in some lines with multiple quote fields

i want to replace mistaken quotes in line starting with tag 300 and relocate the quote in the correct position so the input is
223;25
224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;;
300;X;Event: "419031003804486","76","2010/04/28-06-48-23.00",,,,,,,,,"9697","18744","28441",,,"4676",,,,,,,,,"blackb"e"rry."net,"419031003804486",,"1",,,,,,
Footer: text_data_transfer_file

and i need to replace field #26 in the line starting with 300;X; from "blackb"e"rry."net to "blackberry.net"
so the corrected version from the previous one should be
223;25
224;20100428064823;1;0;0;0;0;0;0;0;8;1;3;9697;18744;;;;;;;;;;;;
300;X;Event: "419031003804486","76","2010/04/28-06-48-23.00",,,,,,,,,"9697","18744","28441",,,"4676",,,,,,,,,"blackberry.net","419031003804486",,"1",,,,,,
Footer: text_data_transfer_file

awk -F","  '/^300;/ {$26=sprintf("%c%s%c", 34, "blackberry.net", 34)}  {print $0} '  oldfile > newfile

this was OK ,
but it is not always "blackberry.net" , it could be other values
for example :
300;X;Event: "204043100439143","76","2010/05/31-22-58-48.00",,,,,,,,,"155","104","259",,,"281",,,,,,,,,E"MGS"M.VZW3G".COM
,"204
043100439143",,"1",,,,,,

awk -F, '/^300/ {gsub(/"/,"",$26);sub(/.*/,"\"&\"",$26);print;next;} {print;} old.file > new.file
1 Like