18

I am using a couple of documentation files in LibreOffice (.odt) format. Normally, I access them with LibreOffice Writer of course. But there are times when I can only connect to the site with a text terminal.

I am wondering if there is a terminal-based tool that can show me the contents of these files in approximate correct format? (The files mainly contain simple text, bullet lists, and a few 1x1 tables, so it's relatively simple stuff in terms of formatting.)

P.S. This question is not about starting LibreOffice itself from the command line (which is anwered here).

  • 2
    Possible duplicate of how to view a doc from command line? – pLumo Nov 13 '17 at 8:41
  • 3
    Not in the original answer, but you can use odt2txt document.odt | less to directly view the file. – pLumo Nov 13 '17 at 8:47
  • @RoVo That suits for an answer! It would be interesting whether odt2txt does a job as good as libreoffice --convert-to (which I'd expect to work very well without having tried it extensively). The latter (as far as I found out) is not able to write to stdout so that piping directly unfortunately isn't available for it. Caveat: If you just quickly want to view (or search!) the content of your document and maybe don't care too much about formatting, odt2txt | … is the way to go. Else let libreoffice convert your document as explained below. – dessert Nov 13 '17 at 12:25
  • 2
    Simple documents seem to be converted well with both tools. Unfortunately tables are not converted to ascii tables ... – pLumo Nov 13 '17 at 12:34
21

There is a tool called odt2txt that can convert odt to txt.

Compared to libreoffice I can see two benefits:

  • Lightweight if you don't have libreoffice installed (e.g. on a server)
  • It can print to stdout for direct viewing of files.

Installation:

sudo apt install odt2txt

Then you can directly view an odt:

odt2txt document.odt | less
  • If you want to convert to a file just redirect the output with odt2txt document.odt > file or use the --output=file option. – dessert Nov 13 '17 at 16:18
21

libreoffice provides a --convert-to option which can be used to convert a document to e.g. text or html:

  • convert input.odt to input.txt:
    libreoffice --convert-to "txt:Text (encoded):UTF8" input.odt

  • convert every .odt in the current directory to .html:
    libreoffice --convert-to "html:XHTML Writer File:UTF8" *.odt

  • convert every .ods in the current directory to .csv:
    libreoffice --convert-to csv *.ods

The output can be opened with the pager or terminal browser of your liking: less, most or w3m to list just three.

  • Nice! Can you use this to display the txt version directly in terminal instead of writing to a file? – Puck Nov 13 '17 at 16:36
  • Unfortunately not, see my comment above. – dessert Nov 13 '17 at 16:43
12

LibreOffice has a --cat option which exists in version 5.1 but not 4.2. Not sure exactly when it was introduced.

libreoffice --cat "Untitled 1.odt" --headless | less

For more information:

libreoffice --help
  • It's a shame this useful option is neither documented in libreoffice's manpage nor on help.libreoffice.org/Common/…, however at least libreoffice -h lists it. – dessert Nov 13 '17 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.