Convert XLS to CSV in UNIX

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Convert XLS to CSV in UNIX

Post by just4geeks »

I need to grep for a string in a XLS file. And that is why, I need to convert it to a CSV file in a script or something. Is there any UNIX command that does that?

Thanks for your help.
Attitude is everything....
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

By XLS you mean Excel spreadsheet file? If that's the case, you can use perl dbi functionality to do a conversion. I don't think there's native unix support for specific application data files.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Post by just4geeks »

kcbland wrote:By XLS you mean Excel spreadsheet file? If that's the case, you can use perl dbi functionality to do a conversion. I don't think there's native unix support for specific application data files.
Thanks for your response.

Yes, I meant Excel spreadsheet file. Can you please explain a bit more on the perl dbi functionality? I believe we can run perl scripts in korn shell. Can't we?
Attitude is everything....
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

There are free libraries available that can be used in perl scripts, which look amazingly like korn shell scripts, that flatten XLS spreadsheets into CSV files for the worksheets contained therein. They will materialize data out of cells containing functions, as well as do other things. You're on your own on this one, I can't help you much getting it running. There's folks here who've done this and can speak to it more clearly.

You're in for a lot of work, because worksheets don't necessarily translate into CSV (rows of columns) because they're not tightly constrained data models.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Why not just save the xls sheet as csv and then use it. Who ever is responsible for creating these sheets, request them to send you a csv copy. Usually 'they' dont mind.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Cowmix
Charter Member
Charter Member
Posts: 26
Joined: Sat Apr 01, 2006 2:11 am

Post by Cowmix »

kcbland wrote:There are free libraries available that can be used in perl scripts, which look amazingly like korn shell scripts, that flatten XLS spreadsheets into CSV files for the worksheets contained therein. They will materialize data out of cells containing functions, as well as do other things. You're on your own on this one, I can't help you much getting it running. There's folks here who've done this and can speak to it more clearly.

You're in for a lot of work, because worksheets don't necessarily translate into CSV (rows of columns) because they're not tightly constrained data models.
In the past when I have had to extract data from XLS files from within a UNIX environment I used OpenOffice in command line mode. Read this for more details:

http://www.xml.com/pub/a/2006/01/11/fro ... ffice.html
just4geeks
Premium Member
Premium Member
Posts: 644
Joined: Sat Aug 26, 2006 3:59 pm
Location: Mclean, VA

Post by just4geeks »

DSguru2B wrote:Why not just save the xls sheet as csv and then use it. Who ever is responsible for creating these sheets, request them to send you a csv copy. Usually 'they' dont mind.
I could ask them to send me a csv file. I am trying that too. I thought if there is a command to convert xls, then it would be cool to learn. All I need to do is grep for a string. Since the grep command didn't accept a xls file, I need it converted into something that can be understood by grep? All I need is the text. I don't care if the layout is messed up.

thanks for your time.
Attitude is everything....
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

You are rght, you cannot grep an xls file, You need to get the file in a different format like csv-
If your company is willing to make a purchase, there are many products in the market which can convert xls to csv file, even through the command line.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Your problem is the file is binary of a proprietary format, not ASCII text.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply