12

I work a lot with LibreOffice Writer.

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

3
  • 3
    I don't think this is a duplicate. This question asks if there's a text-based Terminal utility for editing .odt files. The other question is about using Terminal to launch a particular .odt file into the full graphical version of LibreOffice Writer.
    – Gaultheria
    Jan 21 '18 at 1:50
  • 1
    IMHO it's probably closer to this cat command doesn't show the lines of the text - which explains how to unzip an odt file to obtain the underlying content.xml file Jan 21 '18 at 2:34
  • The closest thing to what you're looking for is wordgrinder, you can install it executing: sudo apt install wordgrinder, here is the official website of the project, hope it helps.
    – galoget
    Jan 21 '18 at 2:39
8

The closest thing to what you're looking for is wordgrinder, a terminal-based word processor.

You can install it executing:

sudo apt install wordgrinder

Here is the official website of the project: https://cowlark.com/wordgrinder/

This is the Github repo: https://github.com/davidgiven/wordgrinder

And a quick Survival Guide: https://gist.github.com/davidgiven/1aba97e96a9b8f9b573b

If you check the Importing and Exporting sections you will find:

Importing

Imports basic content from ODT files. OpenDocument is complicated and hard to parse but WordGrinder will do its best to apply appropriate styles. Unsupported features are ignored.

Exporting

This produces an ODT file which can be read by LibreOffice and a variety of other major word processors. Character and paragraph styles are exported and are mapped to OpenDocument styles called P, H1, H2 etc.

6

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.

3
  • 1
    If anyone, like me, happens across this and tries wrestling this into .vimrc, this is what worked for me autocmd BufReadPost *.odt silent %!pandoc "%" -tmarkdown -o /dev/stdout autocmd BufWritePost *.odt :%!pandoc -f markdown "%" -o "%:r".odt
    – matt604
    Nov 2 '20 at 17:00
  • This method ruins the .odt's format when converting from .txt to .odt if you converted the original .odt to .txt to edit, and convert it back to .odt.
    – user58029
    Jun 2 '21 at 4:44
  • @user58029 What do you mean by saying “ruins the .odt’s format”? I can’t test it, but I wouldn’t expect text formatting to survive the conversion. If you seek to achieve that, search for conversion to markup languages like markdown or textile instead.
    – dessert
    Jun 3 '21 at 5:24

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.