rici's helpful answer well explains the problem with the original approach.
However, another thing worth mentioning:
man , .
col -b , - , , .
, grep ; awk , -O:
man gcc | col -b | awk -v RS= '/^\s+-O\n/'
POSIX- -O awk BSD/OSX awk, :
man gcc | col -b | awk -v RS= '/^[[:blank:]]+-O\n/'
, , bash manopt , man . ( , .)
:
manopt gcc O
manopt grep regexp
manopt find '-exec.*'
bash function manopt() - ~/.bashrc, :
manopt() {
local cmd=$1 opt=$2
[[ $opt == -* ]] || { (( ${#opt} == 1 )) && opt="-$opt" || opt="--$opt"; }
man "$cmd" | col -b | awk -v opt="$opt" -v RS= '$0 ~ "(^|,)[[:blank:]]+" opt "([[:punct:][:space:]]|$)"'
}
fish manopt():
.
function manopt
set -l cmd $argv[1]
set -l opt $argv[2]
if not echo $opt | grep '^-' >/dev/null
if [ (string length $opt) = 1 ]
set opt "-$opt"
else
set opt "--$opt"
end
end
man "$cmd" | col -b | awk -v opt="$opt" -v RS= '$0 ~ "(^|,)[[:blank:]]+" opt "([[:punct:][:space:]]|$)"'
end