small ruby program that sorts text files in tricky way