LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2011, 03:14 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Free open source CSV format parsing software written in C/C++


Google directed me to the ones written in .Net/C# etc.
Any ideas on the ones written in C/C++?
 
Old 06-01-2011, 03:39 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,723

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
awk/gawk is witten in C. Just use: "awk -F ','".

Evo2.

---------- Post added 2011-06-01 at 17:39 ----------

awk/gawk is witten in C. Just use: "awk -F ','".

Evo2.
 
1 members found this post helpful.
Old 06-01-2011, 04:14 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by evo2 View Post
awk/gawk is witten in C. Just use: "awk -F ','".
Thanks, that shows the power of awk! I found this: http://www.joeldare.com/wiki/using_awk_on_csv_files

Now I have a choice of calling awk through C by system system call. By that'll be a slow process. On the top of that I want the output in a string rather than a file.

I downloaded the awk source code and peeked in at the mammoth code
 
Old 06-01-2011, 04:39 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I've found this: http://code.google.com/p/csv-parser-cplusplus/. It looks promising.
 
1 members found this post helpful.
Old 06-01-2011, 04:46 AM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
and what have you been eating now-a-days for breakfast, BTW? It indeed looks promising, I've just untared it.
 
Old 06-01-2011, 04:55 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Just a couple of coffee cups!
 
Old 06-01-2011, 05:07 AM   #7
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
and I thought you must be having something special in the breakfast to be at your productive best! It is not easy to be on dot, always.

Last edited by Aquarius_Girl; 06-01-2011 at 05:08 AM.
 
Old 06-01-2011, 06:30 AM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,723

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Ahh, sorry I didn't know you were looking for a library: thought you were looking for an executable.

Evo2.
 
Old 06-01-2011, 06:32 AM   #9
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Well, actually I was looking for a "small" program of 15-20 lines which I could embed in my code.

Anyway, you were helpful and thanks for that.
 
Old 06-01-2011, 08:36 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Which CSV formats do you want to parse? There's a good description of CSV formats here. Having delimiters and quotes in the data is common; having line ends in the data adds a level of complexity. If you are interested in deriving an algorithm for C++ from awk please ask and I'll post awk code (which does support line ends in the data).
 
1 members found this post helpful.
Old 06-01-2011, 09:16 AM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,609
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
Don't send C++ to do a camel's business ...
 
Old 06-01-2011, 12:07 PM   #12
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
What about peeking at the 'awk' code in busybox? Or the code that handles IFS in some lightweight shell?
 
Old 06-01-2011, 05:28 PM   #13
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by Anisha Kaul View Post
Google directed me to the ones written in .Net/C# etc.
Any ideas on the ones written in C/C++?
Umm, judging from wikipedia article it shouldn't be that hard to write parser from scratch in C++ (convert any input file into std::list<std::string> or std::vector<std::string> or std::vector<std::vector<std::string>>). using STL or Qt 4 the whole thing will probably take less than 100 (maybe even less than 50) lines. So, is there some kind of problem?
 
Old 06-02-2011, 12:47 AM   #14
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by catkin View Post
Which CSV formats do you want to parse?
This one: http://www.robosuv.com/html/rddf_2004.html

Quote:
Originally Posted by catkin View Post
There's a good description of CSV formats here.
Thanks, will go through that.

Quote:
Originally Posted by catkin View Post
having line ends in the data adds a level of complexity. If you are interested in deriving an algorithm for C++ from awk please ask and I'll post awk code (which does support line ends in the data).
By "line ends" you mean some special characters denoting the end of line? Well that file doesn't have anything other than a '\n' char at the end.

and I am not sure that I have understood what you meant by "deriving an algorithm for C++ from awk". Did you mean that you'll be writing the code for the same in awk and then I'll translate the awk code to C++?
Anyway, I am an awk/sed/bash/perl illiterate. So won't be able to "read" anything you post in awk.

If you do bother to post the awk code [and also do write "what" each line is doing in plain English], it might be helpful in present/future, to either me or to someone else.

Thanks for your concern.

Quote:
Originally Posted by SigTerm View Post
So, is there some kind of problem?
Not any more. Yesterday I went through some of the code of the software colucix posted. They appeared to be using some libraries, so I thought instead of spending time in exploring, understanding and then extracting code from their software, it is better to reinvent the wheel again. So, yesterday itself, I read the first row of the file [accidentally that was the only row in the file at that time ], put it in the std::string and extracted the substr from it on the basis of position returned by find function, of commas. Converted the string to double type by strtod function..

Didn't think that it would be too simple. Actually previously I had to parse an XML file in Qt and the Qt mailing list people told me to use a new class instead of regular one for parsing. And it really took quite an amount of time in writing that code, handling all the conditions etc.

Last edited by Aquarius_Girl; 06-02-2011 at 04:46 AM.
 
Old 06-02-2011, 06:06 AM   #15
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by Anisha Kaul View Post
Didn't think that it would be too simple. Actually previously I had to parse an XML file in Qt and the Qt mailing list people told me to use a new class instead of regular one for parsing. And it really took quite an amount of time in writing that code, handling all the conditions etc.
XML is much more complicated than CSV.

Quote:
Originally Posted by Anisha Kaul View Post
put it in the std::string and extracted the substr from it on the basis of position returned by find function, of commas.
Sounds like you forgot to handle quotes ("). A comma can be within quotes (","), and there can be quotes within quotes (""""). That's the only "difficulty", but it is still fairly trivial to implement. On other hand, if your file doesn't have any quotes, you don't need even that.

Last edited by SigTerm; 06-02-2011 at 06:08 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Linux and Free/Open Source Software: Why Code For Free? Devs Speak! LXer Syndicated Linux News 0 07-29-2009 07:10 PM
LXer: Linux and Free/Open Source Software: Why Code For Free? (part 1) LXer Syndicated Linux News 0 07-24-2009 06:00 PM
LXer: Research Looks at How Open Source Software Gets Written LXer Syndicated Linux News 0 09-21-2006 01:33 PM
LXer: Free and Open Source Software Development Education Materials (for Free!) LXer Syndicated Linux News 0 08-10-2006 02:21 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration