How to convert a text file into a Word document on Linux

Question: I want to prepare a Microsoft Word document on Linux, but of course without using any Microsoft product. Is there a way to convert a text file into a Word document on Linux?

If you want to create a Word document without using Microsoft Word on Linux, one way is to prepare content in a plain text file, and then convert the text file into a Word document.

For this purpose, you can use a command-line utility called pandoc, which converts from one markup format to another from the command line.

Install Pandoc on Linux

On Ubuntu, Debian or Linux Mint:

$ sudo apt-get install pandoc

On Fedora:

$ sudo yum install pandoc

On CentOS, first enable EPEL repo, and then use yum command like above.

Convert a Text File into a Word Document

If you want to apply any formatting to a text file, you can use Markdown syntax in the text. The following is an example of a text file written in Markdown syntax.

My Title
========

Sub-title
---------

This is a new paragraph.  Different paragraphs need to be separated by blank lines.

You can change the attributes of text as follows. *italic*, **bold**, `monospace`.

You can also include a [link](http://example.com).  Note that there must be no space between ] and (.

This is my friend list:

   * Cathy
   * Julia
   * Lisa

This is a numbered list:

   1. Google
   2. Facebook
   3. Apple

You can also include an image file by using the following format.

![alt text](/path/to/image.png "Title")

Once a text file is ready, run the following command to convert the text file into a Word document.

$ pandoc -o output.docx input.txt

This is the output of the generated Word document.

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.

Leave a comment

Your email address will not be published. Required fields are marked *