Solaris, ksh
I have a .csv file I am trying to clean up before loading into the database. The file contains comma separated columns that have leading spaces which I need to remove. The trouble is, some columns that should not be touched are strings which happen to have the same pattern in them. How do I search/replace a comma-space pattern if NOT in a string delimited by double-quotes?
Input row (null first column):
,12345,"first last, MD",Yes,<space>not in use,<space>Other
Desired output:
,12345,"first last, MD",Yes,not in use,Other
The comma-space in the third field (name) should be left alone, but the other columns should have the leading space removed.
This command of course affects the name field which I want to leave alone.
sed 's/, /,/g' x.dat
Note: the third column will be the only column that could be a string. If sed could only operate on columns > 3, that approach would work too.
Thanks for any advice!