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.
2 Answers
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
-
6+1 TIL about Pandoc, which in fact can convert a ton of markup formats into each other.– dessertFeb 7, 2019 at 23:51
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
touch file.docx
you have a docx file. :) What makes a docx file a docx file for you?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.