簡體   English   中英

將手冊頁 output 重定向到文件會導致單詞出現雙字母

[英]Redirecting man page output to file results in double letters in words

我將man djpeg的 output 重定向到一個文本文件中,以便我在學習使用它時可以參考它。 我的指示是man djpeg > textfile.txt 然而,output 看起來像這樣:

LS(1)                     BSD General Commands Manual                    LS(1)

NNAAMMEE
     llss -- list directory contents

SSYYNNOOPPSSIISS
     llss [--AABBCCFFGGHHLLOOPPRRSSTTUUWW@@aabbccddeeffgghhiikkllmmnnooppqqrrssttuuwwxx11] [_f_i_l_e _._._.]

DDEESSCCRRIIPPTTIIOONN
     For each operand that names a _f_i_l_e of a type other than directory, llss
     displays its name as well as any requested, associated information.  For
     each operand that names a _f_i_l_e of type directory, llss displays the names
     of files contained within that directory, as well as any requested, asso-
     ciated information.

     If no operands are given, the contents of the current directory are dis-
     played.  If more than one operand is given, non-directory operands are
     displayed first; directory and non-directory operands are sorted sepa-
     rately and in lexicographical order.

     The following options are available:

     --@@      Display extended attribute keys and sizes in long (--ll) output.

     --11      (The numeric digit ``one''.)  Force output to be one entry per
             line.  This is the default when output is not to a terminal.

     --AA      List all entries except for _. and _._..  Always set for the super-
             user.

     --aa      Include directory entries whose names begin with a dot (_.).

     --BB      Force printing of non-printable characters (as defined by
             ctype(3) and current locale settings) in file names as \_x_x_x,
             where _x_x_x is the numeric value of the character in octal.

     --bb      As --BB, but use C escape codes whenever possible.

[...continues]

還有更多,但你明白了。 為什么它會重復一些字符? 此外,如果有一些 function 執行兩次或緩存刷新不正確,為什么它不重復所有這些?

更簡潔的方法是首先將輸出通過管道傳輸到“col -b”:

man djpeg | col -b > textfile.txt

來源: https : //unix.stackexchange.com/a/15866

'man' 程序最初設計用於在電傳打字機上打印其輸出,並使用疊印來產生粗體字符和下划線效果。 您實際看到的是包含格式為X^HX字符串的文件的效果,其中 ^H 是退格字符。 您還有像_^HX這樣的字符串,用於下划線(因此是 _f_i_l_e)。

這些可以使用像vi這樣的文本編輯器輕松剝離,它將顯示退格。

:%s/_^H//g

將刪除下划線,和

:%s/.^H.//g

粗體(上面的 ^H 是 ctrl-H。您必須使用ctrl-V ctrl-H將這些輸入到 vi 中。

您可以簡單地將STDIN重定向到任何(非)gui 編輯器(支持 stdin 輸入)...字符重復沒有問題

例如(我的前 5 名):

man curl | subl -
man curl | vi -
man curl | vim -
man curl | nano -
man curl | code -
...

PS這不僅是man的用例——任何信息都可以通過這種方式重定向

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM