Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 09-18-2013, 08:01 AM   #1
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!


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 08:09 AM.
Old 09-18-2013, 08:24 AM   #2
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,232

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
this mite help:

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

Rep: Reputation: 128Reputation: 128
Convert CSV to XLSX:
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.


This should get you started on the rest.

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"

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

Rep: Reputation: 2
[QUOTE=pwc101;5029969]Convert CSV to XLSX:
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, 03:52 AM   #5
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:
" Syntax error: "(" unexpected"

What do i do wrong?

Thank you!


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

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

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