2016-11-07 74 views
1

我想只阅读手册页中我正在寻找的部分。使用终端man命令阅读手册页中的章节

例如,要在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. 
+0

是否importen你,得到与-k所有线路,包括对手册页的开头概述的例子,或者是详细参数说明够吗? – sebkrueger

+0

有人提供'男人| sed'/ -k /,/^$ /!d''但是对于'-r' – Benny

+1

工作不正常因为'-r'的附带匹配就像'--regex' ...你可以通过指定将是空格或逗号的下一个字符'man man | sed'/ -k [,] /,/^$ /!d''但显然停在空行并不是干净地给你你想要的东西:S – Zanna

回答

0

你应该考虑你所说的-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来做。

+0

打印所有以符合正则表达式的行开头的行,并以与另一个正则表达式匹配的行结束是“awk”的常见工作,并且可能比编写python脚本更容易。 –