Filed under: Tips and tricks, Terminal Tips
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.
Get a WordPress.com Blog
![TUAW [Cafepress]](http://www.blogsmithmedia.com/www.tuaw.com/media/tuaw-cafepress-promo.png)


Reader Comments (Page 1 of 1)
Twist said 5:46PM on 4-19-2007
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).
Reply
teece said 6:40PM on 4-19-2007
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.
Reply
Billifer said 6:42PM on 4-19-2007
(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
Reply
xSmurf said 8:48PM on 4-19-2007
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
}
Reply
the daniel said 4:58AM on 4-20-2007
and then there's Bwana, which lets you type man:whatever in your browser and get a nicely formatted man page.
Reply
Mike Harris said 2:12PM on 4-22-2007
Very nice tips ... thank you. :)
Reply
Billifer said 10:03AM on 5-14-2007
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.
Reply