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, eg to list what -x
switch of tar
does:
man tar | grep -C5 -- "-x\b"
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.