Created
April 24, 2015 09:42
-
-
Save dcarneiro/28cc4b06787ef1fe8ae4 to your computer and use it in GitHub Desktop.
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
# This shell will get you the top x items for each group | |
# pe: | |
# if you have a csv with user_id, song_id, relevance | |
# this will sort the csv by user_id asc and then by relevance desc | |
# after that it will only print the top x results for each user to STDOUT | |
sort -t, -k 1,1n -k 3,3nr my.csv | awk -F, -v max_items=5 '{if (user_id != $1) {user_id=$1; count=1} ; if (count <= max_items) { print; } ; count+=1;}' > result.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment