![排序並保留 pdftotext 尋找的顏色編碼結果](https://rvso.com/image/168779/%E6%8E%92%E5%BA%8F%E4%B8%A6%E4%BF%9D%E7%95%99%20pdftotext%20%E5%B0%8B%E6%89%BE%E7%9A%84%E9%A1%8F%E8%89%B2%E7%B7%A8%E7%A2%BC%E7%B5%90%E6%9E%9C.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 紅色?正如您所看到的,第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)