7

I want to get only specific sections of MAN page inside a shell (or perl) script and print it.

For eg: only the SYNOPSIS section of MAN page

Is there any standard way to do that?

Regards, Anandan

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Anandan
  • 983
  • 3
  • 13
  • 28

5 Answers5

3

Not as far as I know, but you can search by typing '/' followed by the text you want to search for, then press 'n' repeatedly to go to the next match, or 'N' to go to the previous match.

Cameron
  • 96,106
  • 25
  • 196
  • 225
1

Type the '/' key, then type the string you want to search for (you'll see your query at the bottom of the terminal as you type) and press enter. It'll highlight all the matches and take you to the first one. After that, type '/' and press enter to go to the next match.

rob
  • 6,147
  • 2
  • 37
  • 56
1

I haven't played with Linux/Unix in a long while, but perhaps you can perform a:

man MANPAGE|a2ps -m > grep -A 1000 SYNOPSIS
David Glass
  • 2,334
  • 1
  • 25
  • 35
  • Careful, this will result in a bunch of false positives if you section name is referenced as they often are ("specifies a format string, see the FORMATS section") – cincodenada Jun 23 '21 at 16:33
1

If you want to navigate to a specific section of a man page you can use this handy method:

Definition

man2() { 
  man -P 'less -p ^EXAMPLES' $1
} 

Example

man2 stat
jasonleonhard
  • 12,047
  • 89
  • 66
  • Sadly without any inbuilt facility this is probably the best option, the beginning-of-line anchor is important here. I'd rework this to add the section name as a parameter, but that's pretty trivial. – cincodenada Jun 23 '21 at 16:31
  • 1
    I think so too. The EXAMPLES section is the one targeted here, but we could have just used $1 and $2, possibly even just made the default EXAMPLES with ${1-EXAMPLES} – jasonleonhard Jun 23 '21 at 18:44
1

at the end of a man page you may find something like a command(some-number) where that (some-number) is the section that contains that command in man pages so I use the -K switch (note it is a big K) followed by the specified section number and it works for me:

`man -K section_number  term_or_command`

i.e.

man -K 5 /etc/host.conf