The following perl works for most cases:
open(DATA,'in/my.csv');
while(<DATA>){
if(/(,\s*|^)"[^"]*,[^"]*"(\s*,|$)/){
print "Before: $_";
while(/(,\s*|^)"[^"]*,[^"]*"(\s*,|$)/){
s/((?:^|,\s*)"[^"]*),([^"]*"(?:\s*,|$))/$1 $2/
}
print "After: $_";
}
}
It's looking for:
- (comma plus optional spaces) or start of line
- a quote
- 0 or more non-quotes
- a comma
- 0 or more non-quotes
- (optional spaces plus comma) or end of line
If found, it will then keep replacing the comma with a space until it can find no more examples.
It works because of an assumption that the opening quote will be preceded by a comma plus optional spaces (or will be at the start of the line), and the closing quote will be followed by optional spaces plus a comma, or will be the end of the line.
I'm sure there are cases where it will fail - if anyone can post 'em, I'd be keen to see them...