Sort CSV file based on first column
Using csvsort
.
Install
csvkit
if not already installed.brew install csvkit
Sort CSV by first column.
csvsort -c 1 original.csv > sorted.csv
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.
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