Assume a wrongly formatted csv snippet using semicolons as field terminator:
abc;d" "e"f;"ijk"
According to RFC4180 a dquote inside a field should be represented by two dquotes:
abc;d"" ""e""f;"ijk"
I've tried to achieve this by a sed
script that matches any dquote not preceeded or followed by the field terminator (here ;
):
echo 'abc;d" "e"f;"ijk"' | sed -e 's/\([^;]\)"\([^;]\)/\1""\2/g'
The result is almost good:
abc;d"" "e""f;"ijk"
except the double quote before the e
is not matched and therefore not duplicated.
Can anyone explain me why this doesn't work, since before and after the e
there's no semicolon.