Filtern Sie mithilfe der Pipe nur den Dateipfad (ohne Verzeichnispfad) aus der Ausgabe |

Filtern Sie mithilfe der Pipe nur den Dateipfad (ohne Verzeichnispfad) aus der Ausgabe |

rpm -qpl dhad-9.0.27891-2.x86_64.rpmermöglicht die Anzeige aller Dateipfade und Verzeichnispfade dieses Pakets.

Beispiel für die Ausgabe:

/opt/dhad/tv_bin/wine/lib/wine/winmm.dll.so
/opt/dhad/tv_bin/wine/lib/wine/winspool.drv.so
/opt/dhad/tv_bin/wine/lib/wine/winsta.dll.so
/opt/dhad/tv_bin/wine/lib/wine/wintrust.dll.so
/opt/dhad/tv_bin/wine/lib/wine/ws2_32.dll.so
/opt/dhad/tv_bin/wine/lib/wine/wtsapi32.dll.so
/opt/dhad/tv_bin/wine/share
/opt/dhad/tv_bin/wine/share/wine
/opt/dhad/tv_bin/wine/share/wine/fonts
/opt/dhad/tv_bin/wine/share/wine/fonts/coue1255.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/coue1256.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/coue1257.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/coure.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/couree.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/coureg.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/courer.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/couret.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/cvgasys.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/hvgasys.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/jsmalle.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/jvgasys.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/marlett.ttf
/opt/dhad/tv_bin/wine/share/wine/fonts/smae1255.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/smae1256.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/smae1257.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/smalle.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/smallee.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/smalleg.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/smaller.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/smallet.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssee1255.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssee1256.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssee1257.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssee874.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssef1255.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssef1256.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssef1257.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/ssef874.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sserife.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sserifee.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sserifeg.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sserifer.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sserifet.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sseriff.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sseriffe.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sseriffg.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sseriffr.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/sserifft.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/svgasys.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/symbol.ttf
/opt/dhad/tv_bin/wine/share/wine/fonts/tahoma.ttf
/opt/dhad/tv_bin/wine/share/wine/fonts/tahomabd.ttf
/opt/dhad/tv_bin/wine/share/wine/fonts/vgas1255.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgas1256.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgas1257.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgas874.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgasys.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgasyse.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgasysg.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgasysr.fon
/opt/dhad/tv_bin/wine/share/wine/fonts/vgasyst.fon
/opt/dhad/tv_bin/wine/share/wine/generic.ppd
/opt/dhad/tv_bin/wine/share/wine/l_intl.nls
/opt/dhad/tv_bin/wine/share/wine/wine.inf
/opt/dhad/tv_bin/xdg-utils
/opt/dhad/tv_bin/xdg-utils/LICENSE
/opt/dhad/tv_bin/xdg-utils/README
/opt/dhad/tv_bin/xdg-utils/xdg-desktop-icon
/opt/dhad/tv_bin/xdg-utils/xdg-desktop-menu
/opt/dhad/tv_bin/xdg-utils/xdg-email
/opt/dhad/tv_bin/xdg-utils/xdg-icon-resource
/opt/dhad/tv_bin/xdg-utils/xdg-mime
/opt/dhad/tv_bin/xdg-utils/xdg-open
/opt/dhad/tv_bin/xdg-utils/xdg-screensaver
/opt/dhad/tv_bin/xdg-utils/xdg-settings
/usr
/usr/bin
/usr/bin/viewer
/var
/var/log
/var/log/viewer

Ich möchtenur Dateipfade filtern:

ich versuche :

rpm -qpl dhad-9.0.27891-2.x86_64.rpm | find -type f

Auch :

rpm -qpl dhad-9.0.27891-2.x86_64.rpm|grep -f

Auch :

rpm -qpl dhad-9.0.27891-2.x86_64.rpm |ls -f

Hat alles nicht geklappt.

Antwort1

Das war ja furchtbar. Vorausgesetzt, die Ausgabe ist so sortiert, können wir sie rückwärts betrachten:

  1. Nimm die letzte Zeile
  2. Schneiden Sie alles ab, was hinter dem letzten steht /, und bewahren Sie es auf. Fahren Sie dann mit der nächsten Zeile fort.
  3. Wenn die Zeilenichtgleich dem letzten Verzeichnisnamen, drucken
  4. Verschieben Sie die Ausgabe nach oben und gehen Sie zurück zu Schritt 2.

Um die Reihenfolge beizubehalten, müssen wir auch die Ausgabe umkehren. Glücklicherweise gibt es einen kleinen Befehl namens tac(die Umkehrung von cat), der dies vereinfacht. Wir rufen ihn einfach vor und nach unserem Bash-Skript auf:

... | tac | while read p; do [ "$l" != "$p" ] && echo "$p"; l="$(dirname "$p")"; done | tac

Beachten Sie, dass dies nur funktioniert, wenn wir uns auf die Dateireihenfolge verlassen können. Ich denke, das können wir wahrscheinlich. Ich habe bisher nur Paketdateien gesehen, die so sortiert waren, also gehe ich davon aus, dass dies Standard ist.


Als ich versuchte, dies zu beantworten, begann ich, eine andere Methode mit zu verwenden awk. Ich scheine die meisten meiner Antworten awkheutzutage in -Form zu geben, also hier das Obige, wie es von awk gesehen wird:

... | tac | awk 'l!=$0{print}{sub(/\/[^\/]*$/,"",$1);l=$0}' | tac

Es ist etwas kürzer, aber ich bezweifle, dass es schneller ist.

Antwort2

Es scheint, als wären README und LICENSE Dateien. Sie könnten also versuchen,

rpm -qpl dhad-9.0.27891-2.x86_64.rpm | grep -P '.*\..*|README|LICENSE'

Antwort3

Sie müsstenprüfenjeder Dateipfad, denke ich, zB so etwas wie

some command \
| xargs -I{} sh -c 'test -f "$0" && printf "%s\n" "$0"' {}

oder

while read -r f; do 
  [[ -f "$f" ]] && printf "%s\n" "$f"
done < <(some command)

verwandte Informationen