Skip to Content

Terminal Tip: Output man pages as plain text with col

Ever try to open a man page in TextEdit using man | open -f? You end up with the kind of unreadable repeated characters shown here. This all dates back to the days of dot matrix and daisy wheel printing when the only way you could produce bold type was to repeatedly print characters. Fortunately, there's an easy way to convert man pages into simple, non-redundant text. Use the command-line utility col with the -b flag enabled. For example, man col | col -b | open -f will open the col man page in TextEdit without repeated characters. The -b flag tells col to exclude all but the last character written to any column, ignoring any backspaces and repeats.



Ever try to open a man page in TextEdit using man | open -f? You end up with the kind of unreadable repeated characters shown here. This...
 

Add a Comment

*0 / 3000 Character Maximum

7 Comments

Filter by:
Billifer

xSmurf -- thanks for the tip! If I had actually, oh, read the man page for man, I'd have seen the -t option. It was, ultimately, the -f option to open that was tripping me up, though.

May 14 2007 at 10:03 AM Report abuse rate up rate down Reply
Mike Harris

Very nice tips ... thank you. :)

April 22 2007 at 1:49 PM Report abuse rate up rate down Reply
Daniel

and then there's Bwana, which lets you type man:whatever in your browser and get a nicely formatted man page.

April 20 2007 at 4:49 AM Report abuse rate up rate down Reply
xSmurf

A much nicer solution is

man -t man | open -f -a /Applications/Preview.app

which will render the man page as a nicely formatted pdf and open it in Preview. I have it as a function in my .bash_profile:

pman() {
/usr/bin/man -t ${1} | /usr/bin/open -f -a /Applications/Preview.app
}

April 19 2007 at 8:48 PM Report abuse rate up rate down Reply
Billifer

(I'm using a lot of HTML here, so I hope this comes through OK.)

My preference for easy readability and printing (if so desired) is, for example:


$ groff -mandoc -Tps /usr/share/man/man1/example.1 > example.ps && open -a example.ps


This will convert the man page to PostScript, then open it in Preview where it can be viewed and/or saved as PDF and/or printed. (Unfortunately, the pipeline straight into open -a Preview doesn’t work, so saving it to a file is required as an intermediate step.)

The trick, if you want HTML documentation instead, is to replace -Tps with -Thtml.

I’ve written scripts which accomplish these tasks, actually:
man2ps:
#!/bin/sh

MANSECT='[1|8|2|3|4|5|6|7|9|0p|1p|3p|tcl|n|l|p|o]' # from man.conf
CMD=$1
CMPATH=`man -w $CMD`
PSFILE=`basename $CMPATH | sed -e 's/.${MANSECT}/.ps/'`
MANPSDIR=$HOME/Documents/manpages

if [[ ! -d $MANPSDIR ]]; then
# make a special directory for PS man pages at /Users/<username>/Documents/manpages
mkdir -p $MANPSDIR
fi

/usr/bin/groff -mandoc -Tps $CMPATH > ${MANPSDIR}/${PSFILE}
if [[ $? -eq 0 ]]; then
/usr/bin/open -a Preview ${MANPSDIR}/${PSFILE}
else
echo "Unable to convert manpage for $CMD to PS" >&2
fi`



Usage: man2ps command

April 19 2007 at 6:42 PM Report abuse rate up rate down Reply
teece

If you pipe man into groff, you can also save the man page as HTML, DVI, or PS.

So:

groff -T html -mandoc `man -w man` > man.1.html
open man.1.html

(I use the man -w command to find the actual man file in question, rather than going and finding it myself in /usr/share or wherever).

Handy, every once in a while.

April 19 2007 at 6:39 PM Report abuse rate up rate down Reply
Twist

Or you could just use a man page viewer application like ManOpen which you can copy from and paste into TextEdit (though with a decent viewer like ManOpen I don't see the point of needing TextEdit).

April 19 2007 at 5:46 PM Report abuse rate up rate down Reply
Buy an ad here

Hot Apps on TUAW

Tweets

© 2012 AOL Inc. All Rights Reserved.