LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2013, 09:01 AM   #1
nouse
LQ Newbie
 
Registered: Sep 2013
Posts: 21

Rep: Reputation: Disabled
is it possible to convert txt to xlsx in command line?


Hi there,
Since you guys really helped me with my last issue:

I have this 300+ txt files (containing character-delimited data) that i would like to convert to xlsx. The manual way would include opening the file with LibraOffice, and save it as xlsx.

However, i feel there must be a batch mode?! It is incredibly tedious)

A really nice addon would be the manipulation of the data
(what i do:
- text to columns, using "semicolon" and "tab" as delimiter
- Insert column in A, add numbers 1-n to each line (to preserve original data structure if needed).

But anything that save me some clicks is very welcome.

Thank you so much!


/edit:

cp/mv *.txt *.xlsx did it. Very simple

I need to think about a for loop then. Sorry for bothering.

However, if you have ideas about the other two things (but i would need R for the column adding, i guess).

Last edited by nouse; 09-18-2013 at 09:09 AM.
 
Old 09-18-2013, 09:24 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
this mite help:
https://duckduckgo.com/?q=csv2xls

i never used it ?
 
Old 09-18-2013, 09:36 AM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Convert CSV to XLSX:
Code:
soffice --headless --convert-to xlsx:"Calc MS Excel 2007 XML" somefile.csv
I'll leave the conversion from character delimited to comma delimited to you.

edit:

This should get you started on the rest.

Code:
for file in *.txt; do
    tr "\t;" "," < "$file" | paste -d, <(seq 1 $(wc -l < "$file")) - > "${file%.*}.csv"
    soffice --headless --convert-to xlsx:"Calc MS Excel 2007 XML" "${file%.*}.csv"
done

Last edited by pwc101; 09-18-2013 at 09:46 AM. Reason: Added looped version with extra steps.
 
2 members found this post helpful.
Old 09-18-2013, 01:22 PM   #4
julienfmills
LQ Newbie
 
Registered: Jun 2009
Location: Pennsylvania, USA
Distribution: CentOS, Slackware
Posts: 21

Rep: Reputation: 2
[QUOTE=pwc101;5029969]Convert CSV to XLSX:
Code:
soffice --headless --convert-to xlsx:"Calc MS Excel 2007 XML" somefile.csv

This is great. I wish I had know about this before. Thanks for this.
 
Old 09-19-2013, 04:52 AM   #5
nouse
LQ Newbie
 
Registered: Sep 2013
Posts: 21

Original Poster
Rep: Reputation: Disabled
Dear pwc101,

many thanks for your help. However, two issues occured:

1. The single line
soffice --headless --convert-to xlsx:"Calc MS Excel 2007 XML" somefile.csv
is accepted (i.e. there is no error message), but fails to do anything. No file is produced.
2. I tried to run your script (MANY thanks for your effort, btw) in an executable, but i get:
"ConvertXLSX.sh: Syntax error: "(" unexpected"

What do i do wrong?

Thank you!
 
  


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
Cmd line to convert .doc and .xls to .txt ? frenchn00b Linux - General 2 04-15-2013 01:05 PM
convert command line picture tool benchcomptons Debian 1 07-29-2007 01:14 AM
How do I convert to an Integer with the Command Line? falcon56215 Linux - Software 10 02-17-2007 02:58 PM
convert doc to pdf in command line yumener Linux - Software 4 04-28-2006 09:23 AM
Convert Excel to CVS from command line? technick Linux - Software 0 12-27-2005 04:55 PM


All times are GMT -5. The time now is 06:06 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration