Skip to content

Instantly share code, notes, and snippets.

@dysbulic
Last active July 9, 2017 21:50
Show Gist options
  • Save dysbulic/0c582f00bb62cb7dd924cbb582a1b680 to your computer and use it in GitHub Desktop.
Save dysbulic/0c582f00bb62cb7dd924cbb582a1b680 to your computer and use it in GitHub Desktop.
Unit Sorting
#!/usr/bin/env ruby
puts "Usage: #{$0} [input-file]..." if ARGV.empty?
matches = []
ARGV.each do |path|
begin
File.foreach(path) do |line|
match = /^#?(\d+)([^ ]*) - (.*)/.match(line)
if match
matches << match
elsif not line.strip.empty?
STDERR.puts "Unknown line format: #{line.dump}"
end
end
rescue Errno::ENOENT
STDERR.puts "Couldn't open file: #{path.dump}"
end
end
matches.sort_by!{ |match| [match[1].to_i, match[2]] }
matches.each{ |match| puts match[0] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment