Parsing a CSV Data File
Problem
You have a Comma Separated Values (CSV) data file that you need to parse.
Solution
Unlike the previous recipe for converting to CSV, there is no easy way to do this, since it’s tricky to define exactly what CSV really means.
Possible solutions for you to explore are:
Perl: Mastering Regular Expressions by Jeffrey E. F. Friedl (O’Reilly) has a regex to do this
Perl: See the CPAN (http://www.cpan.org/) for various modules
Load the CSV file into a spreadsheet (OpenOffice.org’s Calc and Microsoft’s Excel both work), then copy and paste into a text editor and you should get tab delimited output that you can now use easily
Discussion
As noted in Converting a Data File to CSV, there is no formal specification for CSV, and that fact, combined with data variations, makes this task much harder than it sounds.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access