Convert a Text File to RTF, HTML, DOC, and more via Command Line

Jul 6, 2011 - 4 Comments

The command line tool textutil allows you to quickly convert text files to many other useful formats. The command syntax you’ll want to use is:

textutil -convert filetype filename

Conversion options are txt, rtf, rtfd, html, doc, docx, odt, wordml, and webarchive, here’s sample syntax converting a text file named test.txt to an rtf:

textutil -convert rtf test.txt

Textutil will automatically append the filename with the appropriate extension. If you want to give the file a new name in the conversion process, use the -output flag as follows:

textutil -convert rtf test.txt -output NewFileName.rtf

If there’s multiple text documents you want to join together into a single new file, use textutil’s built-in cat function:

textutil -cat rtf file1.txt file2.txt file3.txt -output combinedFiles.rtf

You can quickly verify the conversion was successful by opening the newly created rtf file in TextEdit with:

open test.rtf

You can also go the other direction and convert from any of the aforementioned filetypes back to txt, just remember that plaintext does not support any styling so the document will be stripped of any unique fonts, font sizes, styling, or other aspects of a rich text file.

Don’t forget that you can also convert a text file to a spoken audio file, this can be achieved through the command line or by using the simpler “Add to iTunes as Spoken Track” method.

Related articles:

Posted by: William Pearson in Command Line, Mac OS X, Tips & Tricks

4 Comments

» Comments RSS Feed

  1. Viceroy says:

    I like the concatenation aspect but I don’t think I would use the conversions when I can do it through other text editors.

  2. david says:

    viceroy – you can do the concatenation by just using cat

    being a unix admin I love learning new tricks and can see potential benefits in certain cases by using this thanks!

    I think this goes hand and hand with being able to manipulate images and convert to different types try the following to learn more about that.
    sips –help

  3. [...] addition to being able to convert TXT files to RTF or other filetypes, you can use textutil to convert the font family and font size of a document from the command [...]

  4. D L S says:

    Loved it..

    I am a completely new and first Time Mac User and have been a Windows User for almost 10 years.. Just loved learning all this stuff..

    Used to do a lot of such things back when Learnt DOS in Windows

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Shared on Facebook

Shop at Amazon

Ad

OSXDaily on Facebook