首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用终端手册命令阅读手册页中的章节

使用终端手册命令阅读手册页中的章节
EN

Stack Overflow用户
提问于 2016-11-07 21:21:37
回答 1查看 156关注 0票数 1

我只想阅读手册页中我正在寻找的部分。

例如,要仅读取man手册页中的-k部分,我可以使用

代码语言:javascript
复制
man man | grep -E '(-k)'

结果是:

代码语言:javascript
复制
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.

结果很糟糕,因为这不是我需要的所有部分。

所以我现在用的是:

代码语言:javascript
复制
man man | grep -E '(-k|'')'

结果是所有文本,但标记为红色的-k

我的问题是,如何才能获得类似以下内容的输出:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2016-11-07 22:10:54

您应该考虑一下-k (-AnyOther)的各个部分是什么意思

例如,下面的条目如何?:

代码语言:javascript
复制
   -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有关。

根据您的示例,我认为您希望跳过此条目。如果是这样,我建议使用两个正则表达式:

代码语言:javascript
复制
"^\s*-k" # for the case when -k is at the beginning
"man -k" # self explainable :) 

从找到的条目中,您应该打印下面的所有行,第一个可打印字符之前的空格应该比匹配字符中的空格多。

我不确定grep或sed是否是适合这项工作的工具。就我个人而言,我会尝试使用python或awk。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40466255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档