Same solution I have answered here, that will also apply to your question with a bit modification here:
sed -E ':loop s/(\([^)]*),([^)]*\))/\1\2/; t loop' infile
Breaking down:
Note: un-escaped (
or )
outside character class [...]
is to used for grouping match; escaped \(
or \)
or within character class [...]
will match literal (
and )
; ^
is negation match, so [^)]
matches "any single character but not a )
".
then we have:
(\([^)]*)
: first group match, back referend \1
is referring to.
,
: match a single comma.
([^)]*\))
: second group match, back-reference \2
is referring to.
Considering one sample line like below and explaining on how this match works:
c(("4288", "57534", "somtoher")),d("f1", "f2", "f3"),MIB1
this (\([^)]*),([^)]*\))
will match:
from very first open parenthesis (
followed by anything but not a )
and up-to last ,
to the first close parenthesis )
; so, first group match \1
will match (("4288", "57534",
part of the sample line at above;
then anything after last ,
to the first close parenthesis up-to first close parenthesis and )
itself will be in second group match \2
; it will be "somtoher")
part of the sample line above.
in replacement part in \1\2
, we revert the both matched groups back but dropped comma between them.
:loop s///; t loop
; do steps 1 to 3 in until all commas between (
&)
cleared in a sed's loop (loop
is used as label).
at first attempt, our sample line would change to:
c(("4288", "57534" "somtoher")),d("f1", "f2", "f3"),MIB1
at second attempt would be:
c(("4288" "57534" "somtoher")),d("f1", "f2", "f3"),MIB1
at third attempt would be:
c(("4288" "57534" "somtoher")),d("f1", "f2" "f3"),MIB1
and so on.