「少ない」出力のサブセットをエクスポートする方法

「少ない」出力のサブセットをエクスポートする方法

後で使用するためにログファイルのサブセットをインポートしてファイルに保存する必要があることがよくあります。私はless常にログを探して検索しており、興味深い部分をエクスポートするために現在、次のことを行います。

  1. 行番号を表示しless、必要な行範囲を記録します。
  2. CLIに戻り、sedIを使用して目的の範囲を抽出してファイルに保存します。

less内部で(つまり、部品なしで)sedこれを行うことはできますか?

ベストアンサー1

ノート、特定のインストールによっては、次のコマンドが機能する場合と動作しない場合があります。

からman less

   | <m> shell-command
          <m> represents any mark letter.  Pipes a section of the input file to the
          given shell command.  The section of the file to be piped is between the
          first line on the current screen and the position marked by the letter.
          <m> may also be ^ or $ to indicate beginning or end of file respectively.
          If <m> is . or newline, the current screen is piped.

そのため、ファイルを開くときに目的のless場所に移動し、次のように入力します。

|. cat >filename

|.less現在の画面が指定されたコマンドで送信されるようにします。コマンドはですcat >filenamecat読んでSTDINリダイレクトしますfilename

必要に応じてエディタで部品を開くこともできます。

|. vi -

読む理由-。次に、編集する内容を編集し、ファイルを 。viSTDINvi:w filenameSTDIN

おすすめ記事