Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Just for the sake of it...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Just for the sake of it...
Authored by: pmccann on Dec 01, '01 01:23:58PM

ManOpen is fun, but if you were really only after an ascii version of a man page without those headers and footers we should be able to hit it with a pretty simply shell script. Here's a two-liner proof of concept that pretty much does that job.

#!/bin/sh
man $1 | col -b | egrep -i -v "^${1}|^[a-z0-9].*[0-9]+$" | uniq >${1}.ascii

"col -b" kills the formatting (underlines and bold text), the egrep call weeds out lines that either begin with the name of the command or fit the bill as a "footer"; strolling through a few different man pages made it clear that there's no real standard format for this, but I think this part of the regular expression catches most. I think that kills the headers and footers pretty efficiently. Piping to unique just kills repeated lines, which in this situation will be multiple blank lines. Finally the output is thrown into "commandname.ascii" in the working directory. Obviously myriad aspects could be cut and polished (eg, you still get the output file if there's no such man page, but the file is of course empty), but the script below gives the guts of what's needed. To use it you can simply save it as, say, "asciiman" in ~/bin, change its permissions to 755 (or 700, or 500, or....), and enter "rehash". Thereafter simply use

asciiman tcsh

for example, to get a minimal ascii version of the tcsh man page in the file tcsh.ascii

Cheers,
Paul



[ Reply to This | # ]