I'm trying to use sed to find and replace globally in a csv file where every field is delimited by " and separated by , but where some content of a field can also contain ".
I am trying to find the occurrences where the last character in a field is " and insert a space after that so that the field ends with a space instead of a ".
Note that there could be multiple fields in a row where the last character of a field could be ".
As an example, here is some file content (4 rows)...
"123","def","","",""
"456","seven eight "nine" ten","","",""
"789"."twenty thirty sixty "seven"","","",""
"303030","one two "three" "four"","five "six"","",""
and it should become...
"123","def","","",""
"456","seven eight "nine" ten","","",""
"789"."twenty thirty sixty "seven" ","","",""
"303030","one two "three" "four" ","five "six" ","",""
i.e. 3 places where the space was inserted: once in the 3rd row and twice in the fourth row.
Currently I got as far as:
1,$ s/[^,]"",/" ",/g
so it finds all the occurrences but does not preserve the character before the match, so I get the result...
"123","def","","",""
"456","seven eight "nine" ten","","",""
"789"."twenty thirty sixty "seve" ","","",""
"303030","one two "three" "fou" ","five "si" ","",""
How to get the desired output with sed? Or maybe with awk?
Thanks.