2016-11-07 29 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腳本更容易。 –