Let's say I have a sentence like this
The quick, (brown, fox) jumps over, the (lazy, old, dog)
I want to replace all the commas ,
inside parentheses ()
to colons :
, however commas that are not enclosed by parentheses should not be replaced. The output should be like
The quick, (brown: fox) jumps over, the (lazy: old: dog)
Notice that the number of commas and parentheses are not fixed in each sentence. How can use shell related tools (bash, sed, awk etc.) to achieve this result?
I have tried to use sed 's/[^(]*\(([^)]*)\)/\1/g; s/,/:/g'
to make substitution to all matched groups, but not sure how to plug the results back to the original sentence.