I have a CSV file, for example:
bear,1 fish,20 tiger,4
I need to sort it from maximum to least based on what is found in the second column, for example:
fish,20 tiger,4 bear,1
How to sort a file this way?
sort -t, -k+2 -n -r filename
will do what you want.
-t, indicates the field separator as a comma
-t,
-k+2 indicates a field to sort by (field2)
-k+2
-r indicates reverse sorting
-r
-n indicates numerical sort
-n