PDA

View Full Version : Bash Sort numbers



sh85
October 25th, 2009, 08:04 AM
Hi everyone.

I have a file containing a list of names with a numbers attached, in the following format:

Francis,CEO,HQ,15000
Janine,CFO,Finance,12000
Daniel,CIO,IT,12000
Bobby,Manager,IT,7200
Jenny,Secretary,HQ,2000

I am trying to make it sort the numbers at the last fields by either ascending or descending
e.g.

Francis,CEO,HQ,15000
Daniel,CIO,IT,12000
Janine,CFO,Finance,12000
Bobby,Manager,IT,7200
Jenny,Secretary,HQ,2000


For ascending i tried sort -t, -k4 file.txt and my results shows
Daniel,CIO,IT,12000
Janine,CFO,Finance,12000
Francis,CEO,HQ,15000
Jenny,Secretary,HQ,2000
Bobby,Manager,IT,7200

what did i do wrong? why does it not sorts the last field?

ghostdog74
October 25th, 2009, 08:15 AM
you must make it sort by numeric, add the -n option

sh85
October 25th, 2009, 08:17 AM
ok. my mistake to overlook the -n option. Thanks anyway ghostdog74