Created
November 18, 2013 03:48
-
-
Save manonthemat/7522153 to your computer and use it in GitHub Desktop.
function to sort a shell history file and print out the lines of commands that has been executed the most
This file contains 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
def sortCommands(histFile, limit=10) | |
file = open(histFile, 'r') | |
lines = file.readlines | |
file.close | |
freqs = Hash.new(0) | |
lines.each do |line| | |
freqs[line] += 1 | |
end | |
a = freqs.sort_by {|k, v| -v}[0..limit] | |
i = 0 | |
limit.times do | |
puts a[i][0] | |
i += 1 | |
end | |
end | |
sortCommands('.histfile') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment