2013-08-10 7 views
5

によって「発見」からソートファイルには、私はラインを持っていますアルファベット順。私はsortに上記の行の出力を直接配管しようとしましたが、その結果、ファイル名はその内容ではなくソートされます。 findの出力を配列に変換してから、sortで処理する必要がありますか?バッシュ:すべてのファイルが返され、パイプの</p> <pre><code>find -maxdepth 1 -type f -iname '*key*' -not -name '*~' </code></pre> <p>は、私は(テキストであるべき)の内容を抽出したい<code>sort</code>に分類される:コンテンツ

[編集]私が望む出力はソートされた内容です。

+2

'xargsの通じパイプはsort''を通じて、その後cat'。 –

+0

ありがとう!それは完璧に働いた –

答えて

8

はそれを行うためのいくつかのより多くの方法があります。

  1. find -maxdepth 1 -type f -iname '*key*' -not -name '*~' -exec cat {} \; | sort
  2. find -maxdepth 1 -type f -iname '*key*' -not -name '*~' | xargs cat | sort
  3. cat $(find -maxdepth 1 -type f -iname '*key*' -not -name '*~') | sort
0

あなたがしようと、ファイルにソートされた出力を保存したい場合:

find -maxdepth 1 -type f -iname '*key*' -not -name '*~' | cat | sort > sorted.txt 

そうちょうど> sorted.txtを取り除くと、ソートされた出力は端末ウィンドウに出力されます。ここで完全に期すため

関連する問題

 関連する問題