Skip to content

Instantly share code, notes, and snippets.

@jonyesno
Created December 9, 2010 10:00
Show Gist options
  • Save jonyesno/734553 to your computer and use it in GitHub Desktop.
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
#!/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