我只想阅读手册页中我正在寻找的部分。
例如,要仅读取man手册页中的-k部分,我可以使用
man man | grep -E '(-k)'结果是:
man -k [apropos options] regexp ...
man -k printf
-k, --apropos
which in turn overrides the $PAGER environment variable. It is not used in conjunction with -f or -k.结果很糟糕,因为这不是我需要的所有部分。
所以我现在用的是:
man man | grep -E '(-k|'')'结果是所有文本,但标记为红色的-k。
我的问题是,如何才能获得类似以下内容的输出:
man -k [apropos options] regexp ...
man -k printf
Search the short descriptions and manual page names for the keyword printf as regular expression. Print out any matches.
Equivalent to apropos printf.
-k, --apropos
Equivalent to apropos. Search the short manual page descriptions for keywords and display any matches. See apropos(1)
for details.发布于 2016-11-07 22:10:54
您应该考虑一下-k (-AnyOther)的各个部分是什么意思
例如,下面的条目如何?:
-P pager, --pager=pager
Specify which output pager to use. By default, man uses pager -s. This option overrides the $MANPAGER environment variable, which in turn overrides the $PAGER environment variable. It
is not used in conjunction with -f or -k.它在某种程度上也与-k有关。
根据您的示例,我认为您希望跳过此条目。如果是这样,我建议使用两个正则表达式:
"^\s*-k" # for the case when -k is at the beginning
"man -k" # self explainable :) 从找到的条目中,您应该打印下面的所有行,第一个可打印字符之前的空格应该比匹配字符中的空格多。
我不确定grep或sed是否是适合这项工作的工具。就我个人而言,我会尝试使用python或awk。
https://stackoverflow.com/questions/40466255
复制相似问题