LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   grepping all manfiles (http://www.linuxquestions.org/questions/linux-software-2/grepping-all-manfiles-506325/)

pgrodt 11-30-2006 04:02 PM

grepping all manfiles
 
From man(1):
Quote:

man uses a sophisticated method of finding manual page files, based on the invocation options and environment variables, the /etc/man.config configuration file, and some built in conventions and heuristics.
So obviously, the manfiles aren't all in a single directory tree. So is there a nice terse command I can use to be able to grep through all manual page files as defined by these settings?

I'll write a script if I have to, but I'd like to avoid it so I can do it on whatever box I'm faced with. My linux/bash skillz are getting better all the time, but they aren't yet good enough to figure this one out.

matthewg42 11-30-2006 04:12 PM

The manual comes with two commands for identifying pages which contain keywords:
Code:

man -k searchterm
apropos searchterm

It's not quite like grep, but it might do what you want?

pgrodt 11-30-2006 04:14 PM

No, I know about apropos, but far too often it returns "nothing appropriate". I like my regular expressions.

pgrodt 11-30-2006 10:27 PM

Well, I worked on it a bit more. Here's the best I've come up with so far:
Code:

$ find `man -w | tr : ' '` -name '*' | xargs zgrep [ GREP_OPTIONS ] [ -e ] PATTERN
it's popping up some error messages about not being able to find the occasional path/name.n.gz which is vexing as in those cases path/name.n already exists. Anyway, can anyone beat that command?

matthewg42 12-01-2006 05:11 AM

Quote:

Originally Posted by pgrodt
No, I know about apropos, but far too often it returns "nothing appropriate". I like my regular expressions.

apropos will allow you to search for regular expressions:
Code:

apropos -r some_re
Or you can search for shell-style glob wildcards:
Code:

apropos -w 'some_wilcard*'
If you still want to do it yourself for fun, here's how I would approach it.
  1. All the following in a Perl script
  2. Parse /etc/manpath.sections - extract SECTIONS and base PATH
  3. Make a list of MANDATORY_PATHs
  4. Add the list from the MANPATH environment variable if defined
  5. Iterate over the list of paths adding sections. This'll give you the list of directories to search
  6. Iterate over the list of directories opening files with gunzip if necessary, and extracting the info you want. Be aware the manpage markup is a little weird.

pgrodt 12-01-2006 09:00 AM

hmm...my apropos has no options...Probably because it dates back from 1991. Well that's interesting.

I only know a little about the manpage markup. I suppose I can send it to man2html and then parse past the tags pretty easily...

matthewg42 12-01-2006 09:19 AM

You could use nroff -man to process them too. Thing is, parsing thousands of man pages will take quite some time. You'll probably want to build an index and search that with your tool. If you do that, you'll need some sort of index update job. This is a similar approach to updatedb/locate.

pgrodt 12-01-2006 10:29 AM

aha yes. This helps. I haven't used groff/nroff much yet.

matthewg42 12-01-2006 10:40 AM

If your system uses catman, you'll have pre-processed versions of some files, which could save you quite a bit of time.


All times are GMT -5. The time now is 11:25 AM.