1

I have a file in following format. I need to sort it by largest code first and then by largest values column.

 colour,letter,code,value
    red,r,016,949.8
    red,r,015,603.9
    red,r,014,348.4
    blue,b,016,362.29
    blue,b,015,460.2
    blue,b,014,9850.9

output:
    red,r,016,949.8
    blue,b,016,362.29
    red,r,015,603.9
    blue,b,015,460.2
    blue,b,014,9850.9
    red,r,014,348.4

my implementation

sort  -k3,3n -r  -k4,4n -t \t data.csv  

When I try to do it it sorts the file but doesn't sort the first two columns.

1

1 Answer 1

2

It's not clear if the file is TSV (tab separated), or CSV (comma separated). Question indicate CSV, but answer using tab delimiter (-t \t). Try -t, for CSV. Also the reverse order need to be applied to each key ('r' suffix on each key).

sort -k3,3nr -k4,4nr -t, data.csv
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.