Skip to main content
added 204 characters in body
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

Maybe you can put quotes around the fields, which should tell csv parsers that the commas inside are not field separators:

sed 's/"/""/g;  # escape existing " as "" s/[[:space:]]*,[[:space:]]*/","/; # replace the first , and the # whitespace around it with ","  s/^[[:space:]]*/"/; # add a " at the start (and # get rid of whitespace there)  s/[[:space:]]*$/"/'; # same at the end' 

Maybe you can put quotes around the fields, which should tell csv parsers that the commas inside are not field separators:

sed 's/"/""/g; # escape existing " as "" s/[[:space:]]*,[[:space:]]*/","/ s/^[[:space:]]*/"/ s/[[:space:]]*$/"/' 

Maybe you can put quotes around the fields, which should tell csv parsers that the commas inside are not field separators:

sed 's/"/""/g;  # escape existing " as "" s/[[:space:]]*,[[:space:]]*/","/; # replace the first , and the # whitespace around it with ","  s/^[[:space:]]*/"/; # add a " at the start (and # get rid of whitespace there)  s/[[:space:]]*$/"/; # same at the end' 
Source Link
Stéphane Chazelas
  • 586.8k
  • 96
  • 1.1k
  • 1.7k

Maybe you can put quotes around the fields, which should tell csv parsers that the commas inside are not field separators:

sed 's/"/""/g; # escape existing " as "" s/[[:space:]]*,[[:space:]]*/","/ s/^[[:space:]]*/"/ s/[[:space:]]*$/"/'