Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to sort a comma separated file (with following details) based on salary (ascending or descending)

a.Ename,firstname,lastname,salary 
share|improve this question

2 Answers 2

sort -t, -k4,4 filename

That's for ascending, throw in -r for descending.

share|improve this answer
1  
Probably going to want -n to make the sort numeric, and hopefully you salary numbers don't have commas in them :-) If so, you should paste a few example lines (with names/numbers changed a little to protect the innocent. –  Kyle Brandt Dec 9 '09 at 12:51

In my country the separator is not , but ; - so the solution is more complicated. Just in case this applies here too...:

LC_ALL=C 
export LC_ALL

and instead of -t, I use

--field-separator=\;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.