1

For me, it happens a lot when I want to search for an specific option in man page. I know that options are at the beginning of lines, but don't know how to limit the search.
I've tried /^REG-PATT, but it didn't work for me.

What is the shortest correct pattern that I can use ?

xhienne
  • 5,738
  • 1
  • 15
  • 34
Rsh
  • 7,214
  • 5
  • 36
  • 45
  • I think the full answer to this question is _depends on your system_. `less` is sometimes used for `man` paging, and `less` can be compiled with different regex engines. – pb2q Aug 12 '12 at 18:52
  • I don't think so. It's about searching patterns in `less`. how so ? – Rsh Aug 12 '12 at 18:54
  • from `man less`: _The pattern is a regular expression, as recognized by the regular expression library supplied by your system_. Furthermore your question doesn't specifically mention `less` at all – pb2q Aug 12 '12 at 19:07
  • Thanks for clarification. In that case, I'm using Ubuntu. – Rsh Aug 12 '12 at 20:00

3 Answers3

2

There's some space before the options. Maybe ^\s*-o (-o is the option you are searching) works. Or you can simply search the option in the whole line (-o).

Lord Spectre
  • 761
  • 1
  • 6
  • 21
  • Yeah, that't working, thanks. But it's a little bit awkward, Do you know any other shortcuts instead of typing this every time ? – Rsh Aug 12 '12 at 18:35
  • 3
    I just use `^ *foo` since I haven't ever seen a tab character in a rendered man page. And also... what the... `less` does perl regexps now? Are there any POSIX EREs left in the world? Do people even know that `\s` is non-standard? – Alan Curry Aug 12 '12 at 18:46
  • @AlanCurry I think `^ *-foo` is the closest answer. `^\s*` works on the linux machines that I tried, but not, e.g. on OSX. – pb2q Aug 12 '12 at 19:20
  • @pb2q It depends on the regexp engine used. For example, I tried it with Python's re module and it worked, but it didn't with GNU grep. – Lord Spectre Aug 12 '12 at 19:39
  • 1
    That's my point, the answer to this depends on your system: which pager/regex engine. – pb2q Aug 12 '12 at 19:43
0

grep it out with context, e.g. to list what -x switch of tar does:

man tar | grep -C5 -- "-x\b"

Edit

For getting documentation on -static from gcc(1), you could do something like this with GNU sed:

man gcc | sed -n '/^ *-static/,/^ *-.*/p'

Note that the last line is from the next paragraph.

Here's a more elaborate and precise solution using GNU awk:

man gcc | gawk -v RS='\n\n' -v ORS='\n\n' '
 /(^|\n) *-static/ { state = "printing"    ; print "--" }
!/(^|\n) *-static/ { state = "not printing"             }
state == "printing"
'
Thor
  • 45,082
  • 11
  • 119
  • 130
-2

You might be able to try:

$man command | head

tony.ae
  • 57
  • 2
  • 7