Created
December 9, 2010 10:00
-
-
Save jonyesno/734553 to your computer and use it in GitHub Desktop.
filter ls(1) output for just the highest version of each RPM package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# filter ls(1) output for just the highest version of each RPM package | |
# naively splits the filename into name / version on the first hyphen-followed-by-digit | |
# "tactical" | |
stash = {} | |
while l = gets | |
l.chomp! | |
begin | |
n,v = l.match(/^([\w-]+)-(\d.*)$/)[1,2] # oh yeah baby | |
rescue Exception | |
STDERR.puts "Eh? #{l}" | |
end | |
stash[n] ||= [] | |
stash[n].push(v) | |
end | |
stash.each do |n, a| | |
high = a.sort.last # alphasort, hmm | |
STDERR.puts "#{n} #{high} (#{a.join(',')})" | |
puts "#{n}-#{high}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment