2

This question already has an answer here:

I'm trying to sort a text file using certain columns in the file as a sort key. Since the file doesn't have separators and fields sometimes stick to each other, I have to convert spaces to some distinctive character (like '@') and then extract columns from the whole string as from the field #1. I've stumbled upon a problem that sort orders strings in some manner unknown to me. Example:

$ cat aaa.txt 
@1
@2
 1
 2
1 
2 

Now replace spaces by '@':

$ sed y/\ /@/ aaa.txt
@1
@2
@1
@2
1@
2@

Now try to sort them:

$sed y/\ /@/ aaa.txt | sort
@1
@1
1@
@2
@2
2@

And the result is embarassing. Lexically, '@' must be before or after the '1'. If '@'>'1' then why strings '@1' are before '1@'? If '@'<'1' then why strings '@2' are after '1@'?

marked as duplicate by Gilles, daisy, Renan, n0pe, Mat Mar 8 '13 at 5:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.