Skip to content

Latest commit

 

History

History
20 lines (14 loc) · 676 Bytes

remove_comma_from_values_in_csv_file.md

File metadata and controls

20 lines (14 loc) · 676 Bytes

Remove the comma from the values in a CSV file where the values may have one comma.

sed 's/\("[^,]\{1,\}\),\([^,^"]\{1,\}"\)/\1\2/g' filename

Remove the commas from the values in a csv file where the values may have none or two commas.

sed 's/\("[^,]\{1,\}\),\([^,^"]\{1,\}\),\([^,^"]\{1,\}"\)/\1\2\3/g' filename

Remove the commas from the values in a csv file where the values may have up to two commas. Combine the two from above.

sed -e 's/\("[^,]\{1,\}\),\([^,^"]\{1,\}"\)/\1\2/g' \
    -e 's/\("[^,]\{1,\}\),\([^,^"]\{1,\}\),\([^,^"]\{1,\}"\)/\1\2\3/g' filename

See: https://praveenlobo.com/blog/remove-commas-from-values-in-csv-file/