LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to Linux Subscribe to Newsletters
Linux & Unix > Excerpts >
O'Reilly Book Excerpts: Linux Desktop Hacks

Hacking the Linux Desktop, Part 2

Editor's note: If you didn't get enough Linux tweaks last week from O'Reilly's Linux Desktop Hacks, here are two more hacks from the book to satiate your hacking needs.

View Microsoft Word Documents in a Terminal

moderate icon hack 52 icon

Avoid the load time of OpenOffice.org and view Microsoft Word documents in a terminal.

The simplest way to view a Microsoft Word document in a terminal is to use the catdoc command. But catdoc turns a Word document to plain text, which does little or nothing to preserve the format of the original Word document. Obviously, it's nearly impossible to view a Word document in a terminal exactly the way it would look in Word. Heck, competing word processors have trouble importing Word documents without upsetting the format, and they have the advantage of being a graphical desktop application. But this hack is still a vast improvement over the popular catdoc program, because it preserves at least some of the formatting of the original document by converting the Word document to HTML.

You'll need both the wvWare set of file conversion utilities and the hybrid web browser/pager w3m, along with a little scripting magic to view Word documents in a terminal or console while retaining at least some of the original formatting.

wv, the All-Purpose Word Converter

There is a way to retain at least some of the original formatting while printing the document to the screen. For this, you need a set of utilities under the name of wvWare. You can find the home page for wvWare at http://wvware.sourceforge.net. Packages of wvWare are readily available for almost all Linux distributions, although the package name is usually just wv. For example, if you don't already have it installed on your system, you can install wv in Debian Linux with this command:


# apt-get install wv

Users of the yum package can get the RPM version of wv with this command:


# yum install wv

w3m, the All-Purpose Web Browser/Pager

That's not all you need for this hack. You also need a popular pager/browser called w3m. Packages of w3m should be available for most Linux distributions, and the package name is usually w3m. For example, you can install w3m in Debian Linux with this command:


# apt-get install w3m

Users of the yum package can get the RPM version of w3m with:


# yum install w3m

The w3m program is rather unique in that it is a web browser that works like a pager--that is, you can pipe text into w3m and use w3m to simply page back and forth through the text. Some versions of w3m even render graphics in a frame-buffer console without having an X Windows desktop running.

You can combine the two utilities to get the desired result of viewing a Word document in a terminal. Use wvWare to convert a Microsoft Word document to HTML format, and then pipe the output into the w3m pager to view it. Here's the full command you need to make it work (this command assumes wvHtml.xml is stored in the /usr/lib/wv directory, which might not be the case on your Linux system):


$ wvWare -x /usr/lib/wv/wvHtml.xml document.doc | w3m -T text/html

That's a lot of typing every time you want to view a Word document, so turn it into a script called viewdoc to make it easier to use in the future. Log in as root and use your favorite editor to create the following script:


#!/bin/bash

wvWare -x /usr/lib/wv/wvHtml.xml $1 2>/dev/null | w3m -T text/html

Note the one subtle addition, 2>/dev/null. This simply redirects any error messages to the twilight zone so that they do not interfere with the presentation of the Word document. Store it as /usr/local/bin/viewdoc and make the script executable with this command:


# chmod +x /usr/local/bin/viewdoc

Now all you have to do to view a Word document in a text console or terminal is issue this command:


$ viewdocdocument.doc

Not only does this technique preserve at least some of the formatting of a Word document, but also, hyperlinks are live and you can activate them to visit the URL from within the w3m viewer you're using to view the document. Figure 7-3 shows an example of a Word document viewed with w3m. Note both the bold headings and the live link to http://www.bootsplash.de/files.

A Word document viewed in HTML text format
Figure 7-3. A Word document viewed in HTML text format

Linux Desktop Hacks

Related Reading

Linux Desktop Hacks
Tips & Tools for Customizing and Optimizing your OS
By Nicholas Petreley, Jono Bacon

Pages: 1, 2

Next Pagearrow




Tagged Articles

Post to del.icio.us

This article has been tagged:

linux

Articles that share the tag linux:

Managing Disk Space with LVM (74 tags)

Use Your Digital Camera with Linux (60 tags)

mdadm: A New Tool For Linux Software RAID Management (59 tags)

Asterisk: A Bare-Bones VoIP Example (43 tags)

View All

Recommended for You

  1. Cover of Run Your Own Web Server Using Linux & Apache
    Run Your Own Web Server Using Linux & Apache
    Print: $39.95
  2. Cover of Linux in a Nutshell
    Linux in a Nutshell
    Print: $49.99
    Ebook: $35.99
  3. Cover of Linux Desktop Hacks
    Linux Desktop Hacks
    Print: $24.95
    Ebook: $19.99
  4. Cover of Linux Cookbook
    Linux Cookbook
    Print: $39.95

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2010, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com