繁体   English   中英

使用Terminal man命令从Manual Page中读取部分

[英]Read sections from Manual Page using Terminal man command

我想在手册页中只阅读我要查找的内容。

例如,只读我可以使用的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.

您应该考虑-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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM