Script to Check & Edit Content of a file (Addition of comma in each lines of code)

Hi all,

I need to write an automated bash shell script which performs such operations:

  1. Grep the header of everyline with the initial of "T" in "FILE_A"
  2. Perform a for loop,
    Count the numbers of comma in the line of code,
    if (no. of comma < 17)
    ADD the comma until 17;
    save a new copy of the file with the new name of <fileName>_NEW;
    else (if more than 17, Do nothing);

*p.s.: meaning that, each line with the header of "T" must have 17 commas.

correct example: T,XXXXX,X,"XXXX_XXXXX_XXXX",F,Y,5,1,A,3,-0.001,0.005,,,,,,
incorrect example: T,XXXXX,X,"IO_SHORT",P,Y,0,0 <MISSING COMMA>

I'm kinda of new to this language, please provide some brief explanation regarding the solution that you provided, your attention & effort are deeply appreciated.

Thank you very much & God blessed you all!!!

awk '/^T/{printf $0;for (i=gsub(",",",");i<17;i++) printf ","; printf "\n";next}1' FILE_A > FILE_A_NEW

Or:

awk -F, '/^T/ && NF < 18{NF=18}1' OFS="," FILE_A > FILE_A_NEW