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.
Share
Categories
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
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 Permalink rate up rate down ReplyVery nice tips ... thank you. :)
April 22 2007 at 1:49 PM Report abuse Permalink rate up rate down Replyand 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 Permalink rate up rate down ReplyA 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
}
(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
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.
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 Permalink rate up rate down ReplyHot Apps on TUAW
Deals of the Day
more deals- Altec Lansing Octiv Duo iDock for $48 + free shipping
- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



7 Comments