I want to replace character e.g. ',' with ';' only between two consecutive '[' and ']' using sed or perl linux command.
Input
abcd,e%sa,@ert&,,qet|,[,,efeg,sy bh|slhg],oiuy#,[abh,ohg;,a oiu],ayba
Ouptut
abcd,e%sa,@ert&,,qet|,[;;efeg;sy bh|slhg],oiuy#,[abh;ohg;;a oiu],ayba
I tried to create sed substitution command
echo "abcd,e%sa,@ert&,,qet|,[,,efeg,sy bh|slhg],oiuy#,[abh,ohg;,a oiu],ayba" | sed 's/\[\([^]]*\),\([^[]*\)\]/\[\1;\2\]/g'
Output
abcd,e%sa,@ert&,,qet|,[,,efeg;sy bh|slhg],oiuy#,[abh,ohg;;a oiu],ayba
but it is replacing only once in sub-string between each '[' and ']'.
What mistake I'm doing in the above sed command or any other way to do the same?