Sample Header Ad - 728x90

Find all older versions based on version in filename

1 vote
1 answer
380 views
This is similiar to this question: https://unix.stackexchange.com/questions/185193/remove-the-low-version-number-of-file Unfortunately the solution to the above question does not work for me, example: Files (ls -vr *.pkg.tar.xz): wire-desktop-bin-2.11.2700-1-x86_64.pkg.tar.xz wire-desktop-bin-2.11.2698-1-x86_64.pkg.tar.xz wire-desktop-bin-2.11.2697-1-x86_64.pkg.tar.xz webstorm-2016.3.3-1-x86_64.pkg.tar.xz webstorm-2016.3.2-1-x86_64.pkg.tar.xz visual-studio-code-1.9.0-1-x86_64.pkg.tar.xz visual-studio-code-1.8.1-3-x86_64.pkg.tar.xz pycharm-professional-2016.3.2-1-any.pkg.tar.xz plasma5-applets-thermal-monitor-git-r63.fd41970-1-any.pkg.tar.xz masterpdfeditor-qt5-3.7.10-2-x86_64.pkg.tar.xz masterpdfeditor-4.0.30-1-x86_64.pkg.tar.xz keepass-plugin-keeagent-0.8.1-3-any.pkg.tar.xz jre-8u121-1-x86_64.pkg.tar.xz jdk-8u121-1-x86_64.pkg.tar.xz jabref-3.8.1-1-any.pkg.tar.xz intellij-jdk-8u112b719-1-x86_64.pkg.tar.xz intellij-jdk-8u112b657-1-x86_64.pkg.tar.xz intellij-idea-ultimate-edition-2016.3.4-1-any.pkg.tar.xz intellij-idea-ultimate-edition-2016.3.3-1-any.pkg.tar.xz hstr-git-1.21.r10.gc0d3236-1-x86_64.pkg.tar.xz google-chrome-56.0.2924.87-1-x86_64.pkg.tar.xz google-chrome-56.0.2924.76-1-x86_64.pkg.tar.xz gitinspector-0.4.4-1-any.pkg.tar.xz dropbox-17.4.33-1-x86_64.pkg.tar.xz chromium-widevine-1:1.4.8.962-1-x86_64.pkg.tar.xz Now I need to find (and later remove) all old packages (version number != highest). Using the solution from the other question: ls -vr *.depot | awk -F- '$1 == name{system ("rm \""$0"\"")}{name=$1}' produces this *wrong* result: :: os/x86_64 » ls -vr *.pkg.tar.xz | awk -F- '$1 == name{system ("echo \""$0"\"")}{name=$1}' wire-desktop-bin-2.11.2698-1-x86_64.pkg.tar.xz wire-desktop-bin-2.11.2697-1-x86_64.pkg.tar.xz webstorm-2016.3.2-1-x86_64.pkg.tar.xz visual-studio-code-1.8.1-3-x86_64.pkg.tar.xz masterpdfeditor-4.0.30-1-x86_64.pkg.tar.xz intellij-jdk-8u112b657-1-x86_64.pkg.tar.xz intellij-idea-ultimate-edition-2016.3.4-1-any.pkg.tar.xz <----------- intellij-idea-ultimate-edition-2016.3.3-1-any.pkg.tar.xz <----------- google-chrome-56.0.2924.76-1-x86_64.pkg.tar.xz Notice this lists *both* idea-ultimate-edition packages because of intellij-jdk (awk splits at first -). I don't really know how to solve this problem consistently. These are Arch Linux packages, even if pacman (Arch Linux package manager) could help me here, I am building and storing them on a Debian system, so I would prefer a pure bash/awk/etc. solution.
Asked by dav1d (113 rep)
Feb 2, 2017, 07:35 PM
Last activity: Nov 7, 2024, 12:15 AM