27

Is there a way to cat or less a .odt file just as antiword does for .doc files?

6 Answers 6

37

The solution is using odt2txt. Now, this command is provided by two different packages, namely one called odt2txt that you can install with

sudo apt-get install odt2txt 

and by the package unoconv (that offers also command-line conversions between more libreoffice formats), that is installed by

sudo apt-get install unoconv

If you have the two, you can switch between them using the alternative mechanism:

sudo update-alternatives --config odt2txt

If you are using the odt2txt provided by the package odt2txt you just use

odt2txt file.odt

if using the unoconv provided package you have to use

odt2txt --stdout file.odt

Pipe them to less to have a less-like experience (odt2txt file.odt | less)

Notice that if you do not use the --stdout option, the unoconv-provided package will write the result in a file called file.txt.

The suggested package by the distribution seems to be the one from the odt2txt package (it has a higher default priority in the alternative system); for sure it has less dependencies.

4
  • Fantastic, thank you! Yes, I've installed the odt2txt package and it behaves as it should.
    – Avio
    Nov 7, 2014 at 13:26
  • The problem with unoconv, as I have discovered, is that it wants to install an older version of Libre Office if you have a newer one installed. Therefore, stick with sudo apt install odt2txt. Nov 11, 2014 at 17:43
  • @PaddyLandau I heavily edited the answer, thank for the hint.
    – Rmano
    Nov 11, 2014 at 18:12
  • @Rmano You have also taught me about update-alternatives, thank you. Nov 12, 2014 at 5:51
7

odt2txt file.odt

the source code and compilebale working zip can be downloaded here:

https://github.com/dstosberg/odt2txt/

or installed by sudo apt-get install odt2txt

7

You can browse through text without any special utility. ODT file is a renamed zip archive. Unzip it and you will see several files. One of them, content.xml contains all text and is more or less readable.

2

You can't cat or less or more an .odt file because it's a binary file. It's actually - as was said earlier - a renamed .zip archive, so you have to extract the content.xml file, but that, as it implies, is an XML document, so you have to process it as such to extract the information out of it.

1

It is also possible with LibreOffice's own command line tool:

loffice --convert-to txt f.odt && less f.txt
1

At least since LibreOffice 6.0, the flag --cat can be used for this.

libreoffice --cat your_file.odt

Be aware that LibreOffice Writer must be closed in order for the command to work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .