Issue
lets say that I have a file as below:(comma separated)
cat test.csv
Rohit,India
Rahul,India
Surya Kumar,India
Shreyas Iyer,India
Ravindra Jadeja India
Rishabh Pant India
zzabc,abc
Now I want to check if the above file is sorted on 02nd column. I tried the command sort -ct"," -k2,2 test.csv I'm expecting it to say disorder in last line, but it is giving me disorder in 02nd line. Could anybody tell me what is wrong here? and how to get the expected output?
Solution
The sort is not guaranteed to be stable. But some implementations of sort
support an option which will force that. Try adding -s
:
sort -sc -t, -k2,2 test.csv
but note that I would expect the first out of order line to be Ravindra Jadeja India
, since the 2nd field of that line is the empty string which should sort before "India".
Answered By - William Pursell Answer Checked By - Timothy Miller (WPSolving Admin)