
結果を並べ替えないことを除けば完璧に機能する 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)