![pdftotext find からの色分けされた結果を保持したまま並べ替える](https://rvso.com/image/168779/pdftotext%20find%20%E3%81%8B%E3%82%89%E3%81%AE%E8%89%B2%E5%88%86%E3%81%91%E3%81%95%E3%82%8C%E3%81%9F%E7%B5%90%E6%9E%9C%E3%82%92%E4%BF%9D%E6%8C%81%E3%81%97%E3%81%9F%E3%81%BE%E3%81%BE%E4%B8%A6%E3%81%B9%E6%9B%BF%E3%81%88%E3%82%8B.png)
結果を並べ替えないことを除けば完璧に機能する find コマンドがあります。path = 検索するフォルダーへのパス foo = 検索語
find /path/ -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color -i "foo"' \;
結果(私の画面では「foo」が赤く表示されます)
me@myComp ~ $ find /path/ -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color -i "foo"' \;
/path/lesson 05.pdf:a foo
/path/lesson 05.pdf: (to have) a foo when I was 10 years old.
/path/lesson 07.pdf:a foo
/path/lesson 07.pdf:Elephant – foo – heavy
/path/lesson 07.pdf:Elephant – foo – heavy – light
/path/lesson 07.pdf:tigers – high – foos – to jump
/path/lesson 04.pdf:10 My foo (not to eat) fat.
/path/lesson 06.pdf:A: John lost the foos collar. B: Is this its ? (rarely used)
/path/lesson 06.pdf:A: This is my foo. .......... is a chihuahua. .......... name is Sleeper.
foo を赤のままにして、パス/ファイル名で結果をアルファベット順に並べ替える方法はありますか? ご覧のとおり、lesson 04.pdf は lesson 07.pdf と lesson 06.pdf の間にあります。
最後に | sort を使用すると、foo が赤でなくなることを除いて、目的の結果が得られました。
どうもありがとうございます
答え1
これで望みどおりの結果が得られたと思います:
while read file; do pdftotext "$file" | grep --with-filename --label="$file" --color -i "foo"'; done < <(find /path/ -name '*.pdf' | sort)