Replace a value after 13th comma in a string

Suppose

b=50,0,0,40,1,0,5000,gold,0,0,0,0,32,9,2,0,10000,0,0,0,0,0,0,0,0,0,BSNL_SMS_Bundle ,null,null,null,null,null,null,null,null,null,0,0,0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,0,0,null,null,0,0,405564245,0

c=11

After 13th comma, the value of 9 needs to be changed and to be filled by another variable c and then b should look like:

b= 50,0,0,40,1,0,5000,gold,0,0,0,0,32,11,2,0,10000,0,0,0,0,0,0,0,0,0,BSNL_SMS_Bundle ,null,null,null,null,null,null,null,null,null,0,0,0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,0,0,null,null,0,0,405564245,0

This value is not constant... it changes with every query

Can anyone please help me out on this.

Hi.

$ c=11
$ echo $b | awk -F, -vOFS=,  \$14=$c
50,0,0,40,1,0,5000,gold,0,0,0,0,32,11,2,0,10000,0,0,0,0,0,0,0,0,0,BSNL_SMS_Bundle ,null,null,null,null,null,null,null,null,null,0,0,0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,0,0,null,null,0,0,405564245,0

It's the 14th field :wink:

thanks scott
but i wanted to save it in the variable, your command is just displaying the $b with a temporary replacement by $c of the 14th variable.

i tried:

$ b=`echo $b | awk -F, -vOFS=,  \$14=$c`

but a syntax error comes saying 4=11

Can you please tell, how i can rectify this

Hi.

Another good reason not to use back-quotes!

$ b=$(echo $b | awk -F, -vOFS=,  \$14=$c)

$ echo $b
50,0,0,40,1,0,5000,gold,0,0,0,0,32,11,2,0,10000,0,0,0,0,0,0,0,0,0,BSNL_SMS_Bundle ,null,null,null,null,null,null,null,null,null,0,0,0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,0,0,null,null,0,0,405564245,0

thank you so much. :slight_smile: