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
Get bash Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.