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 21 2 Now replace spaces by '@':$ sed y/\ /@/ aaa.txt@1@2@1@21@2@Now try to sort them:$sed y/\ /@/ aaa.txt | sort@1@11@@2@22@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@'?
Unexpected ordering of strings in `sort` command
sort