Jump to content

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


Recommended Posts

Posted

<div class="KonaBody"><p>The <a href="http://osxdaily.com/category/command-line/">command line</a> tool textutil allows you to quickly convert text files to many other useful formats. The command syntax you’ll want to use is:</p>

<p><code>textutil -convert filetype filename</code></p>

<p>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:</p>

<p><code>textutil -convert rtf test.txt</code></p>

<p>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:</p>

<p><code>textutil -convert rtf test.txt -output NewFileName.rtf</code></p>

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

<p><code>textutil -cat rtf file1.txt file2.txt file3.txt -output combinedFiles.rtf</code></p>

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

<p><code>open test.rtf</code></p>

<p>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.</p>

<p>Don’t forget that you can also convert a text file to a <a href="http://osxdaily.com/2011/06/28/convert-a-text-file-into-spoken-audio/">spoken audio file</a>, this can be achieved through the command line or by<a href="http://osxdaily.com/2011/06/29/convert-text-to-spoken-audio-the-easy-way/"> using the simpler “Add to iTunes as Spoken Track” method</a>.</p>

</div>

<p><a href="http://feedads.g.doubleclick.net/~a/XEIB52D-x7EtBbCHbDtjvnCJOyk/0/da"><img src="http://feedads.g.doubleclick.net/~a/XEIB52D-x7EtBbCHbDtjvnCJOyk/0/di" border="0" ismap="true"></img></a><br/>

<a href="http://feedads.g.doubleclick.net/~a/XEIB52D-x7EtBbCHbDtjvnCJOyk/1/da"><img src="http://feedads.g.doubleclick.net/~a/XEIB52D-x7EtBbCHbDtjvnCJOyk/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">

<a href="http://feeds.feedburner.com/~ff/osxdaily?a=-1Q9nCc7SqQ:l2P75ZCzG3U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=-1Q9nCc7SqQ:l2P75ZCzG3U:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=-1Q9nCc7SqQ:l2P75ZCzG3U:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=-1Q9nCc7SqQ:l2P75ZCzG3U:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=-1Q9nCc7SqQ:l2P75ZCzG3U:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=-1Q9nCc7SqQ:l2P75ZCzG3U:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=-1Q9nCc7SqQ:l2P75ZCzG3U:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=qj6IDK7rITs" border="0"></img></a>

</div><img src="http://feeds.feedburner.com/~r/osxdaily/~4/-1Q9nCc7SqQ" height="1" width="1"/>

 

View the full article

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days


×
×
  • Create New...