15

I know I can easily create a docx file with libreOffice, but I just want to learn more about using bash. Anyone able to explain if it is even possible with the terminal? The touch command does a decent job but it does not specify any extension.

6
  • 3
    File extensions don’t really matter in Ubuntu, so if you touch file.docx you have a docx file. :) What makes a docx file a docx file for you?
    – dessert
    Feb 7, 2019 at 23:27
  • 6
    touch command lets you specify the extension; touch foo.docx, but that will create an empty file. Is that what you want? Otherwise, loffice --convert-to docx foo.odt will work in a terminal.
    – waltinator
    Feb 7, 2019 at 23:28
  • 4
    @dessert docx is a file format: Office Open XML
    – wjandrea
    Feb 7, 2019 at 23:48
  • 3
    "Anyone able to explain if it is even possible with the terminal?" FYI: odt, docx, xlsx are containers. You can gunzip them and have the human readable version of it. Well human readable ... it is an xml and a large one.
    – Rinzwind
    Feb 8, 2019 at 15:00
  • 3
    If your objective is learn bash, this isn't a bash operation. Using 3rd party tools in bash isn't using bash. If you want to learn bash, try to combine 2 or more separate tools into something useful. You don't even need bash to do this.
    – Braiam
    Feb 8, 2019 at 18:03

2 Answers 2

30

According to this thread over at Unix & Linux, you can use Pandoc.

From skimming the documentation, I think you could use it like:

echo "Hello" | pandoc -o out.docx

Then out.docx will be a docx file with "Hello" in it.


As well, I found this Python module: python-docx

1
22

LibreOffice comes with a command-line tool called soffice which has libreoffice pointing to it, this tool has a --convert-to option which lets you easily convert files in the same way the GUI program does, e.g.:

libreoffice --convert-to docx file.txt

This creates the file file.docx in Office Open XML Text format in the current directory.

Usage example

$ echo some text > file.txt
$ libreoffice --convert-to docx file.txt 

convert /home/dessert/file.txt -> /home/dessert/file.docx using filter : Office Open XML Text
$ file file.docx 
file.docx: Microsoft OOXML
0

You must log in to answer this question.

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