You can use capture groups to match and replace anything that is between double quotes and followed immediately by double quotes.
The regex to match would look something like this: ("[^",]*")"
. Note two things: the first one is that "
are matched literally and the expression in the middle [^",]*
just means that the regex will match anything except a "
or a ,
. This means it will prevent the matched string from having a quote inside.
Lastly, the parenthesis are a capture group and we can reference anything that matched the sub-regex between the ()
with a backslash and a number. For example, \1
will be replaced by the match of the first capture group, \3
with the third and so on.
The sed script for what you need may look something like this:
sed -re 's/("[^",]*")"/\1/g'
See how the last double quote is outside the capture group, and it will not be replaced with the \1
.
Capture groups are a feature of Extended Regular Expressions (ERE), so the flag -r
is needed to enable them in sed, otherwise it will use Basic Regular Expressions (BRE).
Notice also the /g
at the end. This is needed for sed to be able to match and replace more than one occurrence in the same line.
Example:
$ cat test
"ABC-DEF-d98263","12345678","176568981","","588","ABC-DEF-11947","","GAUZE PACKING STRIPS 1/4"","","","2019-02-04T19:09:00-05:00",""","XXX","XXX","2019-02-12T23:57:48-06:00"","XXX-XXX-176568981"
$ cat test | sed -re 's/("[^",]*")"/\1/g'
"ABC-DEF-d98263","12345678","176568981","","588","ABC-DEF-11947","","GAUZE PACKING STRIPS 1/4","","","2019-02-04T19:09:00-05:00","","XXX","XXX","2019-02-12T23:57:48-06:00","XXX-XXX-176568981"