Ubuntu – How to edit a .odt file from the terminal

16.04command linetext-editor

I work a lot with LibreOffice Writer.

I wanted to know if there was a way to edit the text through the terminal?

Best Answer

libreoffice comes with an option to convert an odt file to plain text, which then can be edited with your preferred command-line text editor and (if wanted) converted back to odt.

  1. Convert document.odt:

    libreoffice --convert-to txt document.odt
    
  2. Edit the file with your preferred text editor, e.g.:

    gedit document.txt
    nano document.txt
    vim document.txt
    
  3. Convert it back. The --convert-to takes a filename extension as an argument, but you may also specify a filename suffix to prevent libreoffice from overwriting the original file (which it does without asking!):

    libreoffice --convert-to _new.odt document.txt
    

For the conversion there's also odt2txt, I'd just try both and compare the results.

If you're using vim you can configure it to automatically do the conversion for you in the background, see: Is it possible to easily work with .odt, .doc, .docx, .rtf, and other non-plain-text formats in Vim? The answer there uses odt2txt for the conversion, but it should be possible with libreoffice --convert-to as well.