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 ?

有帮助吗?

解决方案

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).

其他提示

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"
'

You might be able to try:

$man command | head

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top