0

Hi Everyone,

I have the data like below in CSV file

Column1,Column2
A,3
A A,4
A L,5
AIM,6

If i sort the above mentioned date in excel, here is the sorted output:

Column1,Column2
A,3
A A,4
A L,5
AIM,6

But if i tried to sort above data by using Sort in shell script, this is how i got:
Column1,Column2
A,3
A A,4
AIM,6
A L,5

If we notice the output of shell sort command, it seems like omitting white space while sorting.

My requirement is that the data have to be sorted out the way the excel does.

Can you please let me know how to do this shell script?

Thanks in advance

Gopi

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by eggi
0

Your sort is doing a sort by native byte values (space is ascii 32, which is less than the ascii codes for the other characters).

If you can, use the gnu sort (this is the default for linux). It sorts the same way as excel does because it uses your locale setting to determine the sort order.

0

Yes, sort with Gnu does give different results. Also, if you need to, try using the -t option if you need to specifically identify the delimiter that your cells in the csv file are being separated by.
It could be that the default IFS (one or multiple blank spaces) doesn't agree with that.

Best wishes,

Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.