Last active
July 9, 2017 21:50
-
-
Save dysbulic/0c582f00bb62cb7dd924cbb582a1b680 to your computer and use it in GitHub Desktop.
Unit Sorting
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 | |
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