排序並保留 pdftotext 尋找的顏色編碼結果

排序並保留 pdftotext 尋找的顏色編碼結果

我有一個可以完美運行的 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 紅色?正如您所看到的,第04課.pdf位於第07課.pdf和第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)

相關內容