sort a csv file according to a particular n th field numerically (quicker than excel)

sort -t"," -n -k5 file.csv # according to the 5th field NUMERICALLY!!
-n is very important, otherwise it's string comparison
Sample Output
pielberg,Steven,18,dec,1946
Gellar,Sarah_Michelle,14,apr,1977
Bryant,Kobe1,23,aug,1978
Bryant,Kobe4,23,sep,1979
Harnois,Elisabeth,26,may,1979
Underwood,Carrie,10,mar,1983
Ryan,Michelle,22,apr,1984
Belle,Camilla,2,oct,1986
Sharapova,Maria,19,apr,1987
Bryant,Kobe3,23,sep,1998
Bryant,Kobe2,24,aug,2000


the file.csv is:
pielberg,Steven,18,dec,1946
Bryant,Kobe2,24,aug,2000
Gellar,Sarah_Michelle,14,apr,1977
Bryant,Kobe4,23,sep,1979
Harnois,Elisabeth,26,may,1979
Underwood,Carrie,10,mar,1983
Bryant,Kobe1,23,aug,1978
Ryan,Michelle,22,apr,1984
Belle,Camilla,2,oct,1986
Sharapova,Maria,19,apr,1987
Bryant,Kobe3,23,sep,1998

0
By: dexterhu
2011-03-11 09:09:57

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: