![Sortieren unter Beibehaltung der farbcodierten Ergebnisse aus der PDF-to-Text-Suche](https://rvso.com/image/168779/Sortieren%20unter%20Beibehaltung%20der%20farbcodierten%20Ergebnisse%20aus%20der%20PDF-to-Text-Suche.png)
Ich habe einen Suchbefehl, der perfekt funktioniert, außer dass er die Ergebnisse nicht sortiert. Pfad = Pfad zum Ordner, in dem Sie suchen möchten foo = Suchbegriff
find /path/ -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color -i "foo"' \;
Ergebnis (auf meinem Bildschirm ist „foo“ rot)
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.
Gibt es eine Möglichkeit, das Ergebnis alphabetisch nach Pfad/Dateiname zu sortieren und dabei foo rot zu halten? Wie Sie sehen, liegt Lektion 04.pdf zwischen Lektion 07.pdf und Lektion 06.pdf.
Die Verwendung von | sort am Ende führt zu den gewünschten Ergebnissen, außer dass das Foo nicht mehr rot ist.
Vielen Dank
Antwort1
Ich denke, das hier sollte das bewirken, was Sie möchten:
while read file; do pdftotext "$file" | grep --with-filename --label="$file" --color -i "foo"'; done < <(find /path/ -name '*.pdf' | sort)