I have the following CSV file as shown below with 4 columns, and I am taking input of filename from bash terminal.
Sile,Barhams,Female,[email protected]
Shae,Scotti,Male,[email protected]
Shae,Bonham,Female,[email protected]
Shay,Ert,Female,[email protected]
Simeon,Dearle,Male,[email protected]
Desired output is:
Shae,Male
Shae,Female
Shay,Female
Sile,Female
Simeon,Male
Now I tried following code snippets and got the result as shown :
cat $file | cut -d, -f1,3 | sort -k 1,1 -s
Shae,Female
Shae,Male
Shay,Female
Sile,Female
Simeon,Male
cat $file | cut -d, -f1,3 | sort -k 1,1 -s -n
Sile,Female
Shae,Male
Shae,Female
Shay,Female
Simeon,Male
Can somebody explain my both snippets and how I can get desired one please, according to me for first code I am sorting according to first column and in case of tie I have specified stable sort to get the desired output but IDK what is the issue and in second code I wonder how "Sile" appears on the top.
sortimplementation, the--debugoption will likely be of help.Shae's switching order the first time. Sorry.