sorting - Unix sort issue -


can explain why unix sort output differs when delimiter comma',' , pipe '|'

i know applying numeric sort on alphanumeric column think output should not differ when delimiter either comma or pipe.

file comma delimiter:

 $cat file.txt 1,1400002827,002,dc19183529 2,1400002827,002,dc19183500 3,1400004243,001,dc17458621 4,1400008953,004,1459345892 5,1600009991,001,dc17458621 6,1600009991,001,dc17458621 7,1600009991,001,dc17458659 8,1600009991,003,dc17458789  $sort -t, -nuk2,4 file.txt  1,1400002827,002,dc19183529 3,1400004243,001,dc17458621 5,1600009991,001,dc17458621 8,1600009991,003,dc17458789 4,1400008953,004,1459345892 

modified same file have delimiter pipe '|'

 $cat file.txt 1|1400002827|002|dc19183529 2|1400002827|002|dc19183500 3|1400004243|001|dc17458621 4|1400008953|004|1459345892 5|1600009991|001|dc17458621 6|1600009991|001|dc17458621 7|1600009991|001|dc17458659 8|1600009991|003|dc17458789  $sort -t'|' -nuk2,4 file.txt 1|1400002827|002|dc19183529 3|1400004243|001|dc17458621 4|1400008953|004|1459345892 5|1600009991|001|dc17458621 

i don't need alternate solution.
need understand why sort gives different output comma , pipe.

seems problem has shown before.

sort taking commas thousand separators because of -n option. that's why result commas not match result other separators. apparently happens .. if want alphanumeric sort , remove -n option, result same both | , ,.

sort -t'|' -uk2,2 pipes.txt  1|1400002827|002|dc19183529 3|1400004243|001|dc17458621 4|1400008953|004|1459345892 5|1600009991|001|dc17458621  sort -t',' -uk2,2 commas.txt  1,1400002827,002,dc19183529 3,1400004243,001,dc17458621 4,1400008953,004,1459345892 5,1600009991,001,dc17458621 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -