You have a file that has multiple columns separated by a specific delimiter and you need to sort it according to a specific column which need not be the 1st column. If its not the 1st column then ordinary sort wont work. So we need to use the parameters of sort to specify the exact column so that it will sort according to that column only. There are parameters in sort like -t and -k, we use this for the sorting. So -t is to specify the delimiter and -k to specify the column needed. For example : We need to get the 3rd column of a csv file(csv file has , as delimiter) the option should be -t, -k3. We can use two more options for the same. -n for sorting the values as numbers instead of considering as text and -r for sorting in descending order ie biggest value on the top. So the final command is :
sort -nr -k3 -t, columns.csv
Try it out and tell me how it goes.
#1 by Jane Meetington on January 10, 2011 - 8:45 pm
It is certainly interesting for me to read this post. Thank you for it. I like such themes and anything that is connected to this matter. I definitely want to read more on that blog soon.
Jane Meetington