LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 11-30-2006, 04:02 PM   #1
pgrodt
LQ Newbie
 
Registered: Nov 2006
Distribution: RHEL 4 - 2.6.9-42.0.10
Posts: 11

Rep: Reputation: 0
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.
 
Old 11-30-2006, 04:12 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
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?
 
Old 11-30-2006, 04:14 PM   #3
pgrodt
LQ Newbie
 
Registered: Nov 2006
Distribution: RHEL 4 - 2.6.9-42.0.10
Posts: 11

Original Poster
Rep: Reputation: 0
No, I know about apropos, but far too often it returns "nothing appropriate". I like my regular expressions.
 
Old 11-30-2006, 10:27 PM   #4
pgrodt
LQ Newbie
 
Registered: Nov 2006
Distribution: RHEL 4 - 2.6.9-42.0.10
Posts: 11

Original Poster
Rep: Reputation: 0
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?
 
Old 12-01-2006, 05:11 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
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.
 
Old 12-01-2006, 09:00 AM   #6
pgrodt
LQ Newbie
 
Registered: Nov 2006
Distribution: RHEL 4 - 2.6.9-42.0.10
Posts: 11

Original Poster
Rep: Reputation: 0
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...
 
Old 12-01-2006, 09:19 AM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
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.
 
Old 12-01-2006, 10:29 AM   #8
pgrodt
LQ Newbie
 
Registered: Nov 2006
Distribution: RHEL 4 - 2.6.9-42.0.10
Posts: 11

Original Poster
Rep: Reputation: 0
aha yes. This helps. I haven't used groff/nroff much yet.
 
Old 12-01-2006, 10:40 AM   #9
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

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


Reply

Tags
grep, man, manpage


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to access IP addresses when grepping ecampos02 Linux - General 1 11-05-2005 02:39 PM
grepping unknown text, is there a way? vdemuth Programming 15 09-26-2005 03:00 AM
question about grepping something Grafbak Programming 6 03-01-2005 01:28 PM
grepping last word of output rajatgarg Programming 3 11-25-2003 10:41 AM
Not grepping emails right mikeyt_333 Linux - General 11 04-13-2003 02:48 PM


All times are GMT -5. The time now is 10:55 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration