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 ?
Search in Man page for words at the beginning of line
593 Views Asked by Rsh At
3
There are 3 best solutions below
2

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