Skip to content

Instantly share code, notes, and snippets.

@babney
Forked from anonymous/timesorter.rb
Created May 2, 2012 23:13
Show Gist options
  • Save babney/2581456 to your computer and use it in GitHub Desktop.
Save babney/2581456 to your computer and use it in GitHub Desktop.
sorting arrays of "04/03/2012 06:10 PM 4,305 vp.js" and such
preresults = File.readlines("doiton.txt").reject{ |line| line =~ /\d{2}\/\d{2}\/\d{4} \d{2}:\d{2} [PA]M <DIR>|bytes|notes|^$|^01\/\d{2}\/2012|^02\/2[1234567]\/2012|^02\/[01][0123456789]\/2012| Directory of/}
midresults = preresults.map{|line| {:time => DateTime.strptime(line,'%m/%d/%Y %I:%M %p'), :string => line}}
sortedresults = midresults.sort_by{|hash| hash[:time]}
finalresults = sortedresults.map{|hash| hash[:string]}
File.write("rubout2.txt",finalresults.join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment