Dealing with a badly formatted CSV file
Posted
by Josh K
on Stack Overflow
See other posts from Stack Overflow
or by Josh K
Published on 2010-04-15T21:16:35Z
Indexed on
2010/04/15
21:23 UTC
Read the original article
Hit count: 272
I have an exceptionally bad CSV file. Although I "solved" the problem in the end by manually writing scripts to process and reprocess this specific file I wanted to know if there were any other solutions out there.
You have a CSV file that has all the fields terminated by | (pipe) characters. Running a quick check shows you that there are 53 fields in the file. The person who gave you the file claims there there are only 28 fields. Not all of the fields have information in them. For example there are five custom_field_{num} fields which may or may not have data.
How would you get this into a database nicely?
The ideal solution (and one I searched high and low for) would be to just throw it all into a table with no column names or specifications. Then remove any columns that were completely blank and then give them titles and specifications.
© Stack Overflow or respective owner