Is there a way to sort a csv file based on the 1st column using some shell command?
I have this huge file with more than 150k lines hence I can do it in excel:( is there an alternate way ?
To sort CSV by multiple columns, use the sort_values() method. Sorting by multiple columns means if one of the columns has repeated values, then the sort order depends on the 2nd column mentioned under sort_values() method.
To sort CSV by a single column, use the sort_values() method. Set the column using which you want to sort in the sort_values() method.
I don't know why above solution was not working in my case.
15,5 17,2 18,6 19,4 8,25 8,90 9,47 9,49 10,67 10,90 13,96 159,9
however this command solved my problem.
sort -t"," -k1n,1 fileName
sort -k1 -n -t, filename
should do the trick.
-k1
sorts by column 1.
-n
sorts numerically instead of lexicographically (so "11" will not come before "2,3...").
-t,
sets the delimiter (what separates values in your file) to ,
since your file is comma-separated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With