splitting csv into array with IFS
I need to split csv lines into an array of 16 fields. The csv is comma delimited, BUT the field values are also quote delimited.
I can successfully do so with IFS=',' read -a array However; it will obviously fail for values that contain commas. example data: Code:
"32744","STANDARD","Lake Helen",,,"FL","Volusia County","America/New_York","386","28.98","-81.23","NA","US","0","2861", Code:
zip=INSERT_ZIP_HERE How can I properly (and as simply as possible) split the csv line? |
Really crudely; you could see any field that starst with a quote but doesn't end with one needs to be joined up to the neighbours (with an added comma each time) until a closing quaote is found.
|
Well this may be a sucky solution but seems to work without error:
given http://www.unitedstateszipcodes.org/...e_database.csv i'm replacing comma delimiters with a char that should never be used. but not replacing commas within the quoted value: Code:
#replace (",") (,") (",) then remove (") and finally replace lingering field seperators that do not have values - denoted by (,,) (ↈ,) (,ↈ) |
All times are GMT -5. The time now is 10:24 PM. |