Created
April 25, 2013 18:26
-
-
Save andy318/5461940 to your computer and use it in GitHub Desktop.
Read the lines of a csv file and extract a certain field and list the unique values in that field and sort that list based on how many times a value is repeated
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
cdrs = File.readlines ARGV[0] | |
cdrs.shift 1 # Delete the header row | |
cdrs.map! { |x| x.split(',')[3] } # Keep only the callid puts | |
duplicate_callids = cdrs.group_by(&:freeze). # Group by occurence | |
sort_by { |k, v| v.length}.reverse. # Sort by number of occurences desc | |
map { |x| "#{x[0]} - #{x[1].length}" if x[1].length > 1 }. # Format for printing compact | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment