R – Why linux sort is not giving me desired results

csvlinuxshellsorting

I have a file a.csv with contents similar to below

a,b,c
a  ,aa,  a
a b, c, f
a , b, c
a b a b a,a,a
a,a,a
a aa ,a , t

I am trying to sort it by using sort -k1 -t, a.csv
But it is giving following results

a,a,a
a  ,aa,  a
a aa ,a , t
a b a b a,a,a
a , b, c
a,b,c
a b, c, f

Which is not the actual sort on 1st column. What am I doing wrong?

Best Answer

You have to specify the end position to be 1, too:

sort -k1,1 -t, a.csv