bash sort -g does not work properly












5















I am trying to sort a data file in descending order. The data file is given by three columns and I want to order them in descending order for the third column with (the third column is given as a scientific notation in exponential value):



cat eII_surf.txt | sort -gr -k3


Somehow, this worked on a previous machine, but my new one does not seem to do the trick at all.



Here a simple example:



cat test.txt:



6.7 2.3e-12
5.0 3.4e-18
4.5 5.6e-16
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


and cat test.txt | sort -gr -k2:



4.5 5.6e-16
5.0 3.4e-18
6.7 2.3e-12
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


This is the output of locale:



LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC=de_DE.utf8
LC_TIME=de_DE.utf8
LC_COLLATE="en_US.utf8"
LC_MONETARY=de_DE.utf8
LC_MESSAGES="en_US.utf8"
LC_PAPER=de_DE.utf8
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT=de_DE.utf8
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=


Any suggestions and help are highly appreciated! Thanks!










share|improve this question









New contributor




Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • None of the "failed sorted" is in the example input file. What do you get if you sort the example set of data you've shown us? What do you expect to get? Are the columns separated by a tab or by (multiple) spaces?

    – roaima
    2 days ago













  • Is the question supposed to show the input and corresponding output? The data do not match. If you ran the command on a big file and copied parts of the data only, you should instead create a smaller input file and show the expected and actual output for this input.

    – Bodo
    2 days ago








  • 1





    What is the output of locale? (Please add it to your question.) I'm expecting to find that it's one that ignores the - character.

    – roaima
    2 days ago













  • here is the locale output: LANG=en_US.utf8 LC_CTYPE="en_US.utf8" LC_NUMERIC=de_DE.utf8 LC_TIME=de_DE.utf8 LC_COLLATE="en_US.utf8" LC_MONETARY=de_DE.utf8 LC_MESSAGES="en_US.utf8" LC_PAPER=de_DE.utf8 LC_NAME="en_US.utf8" LC_ADDRESS="en_US.utf8" LC_TELEPHONE="en_US.utf8" LC_MEASUREMENT=de_DE.utf8 LC_IDENTIFICATION="en_US.utf8" LC_ALL=

    – Lukas Fuchs
    2 days ago













  • The columns are tab separated

    – Lukas Fuchs
    2 days ago
















5















I am trying to sort a data file in descending order. The data file is given by three columns and I want to order them in descending order for the third column with (the third column is given as a scientific notation in exponential value):



cat eII_surf.txt | sort -gr -k3


Somehow, this worked on a previous machine, but my new one does not seem to do the trick at all.



Here a simple example:



cat test.txt:



6.7 2.3e-12
5.0 3.4e-18
4.5 5.6e-16
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


and cat test.txt | sort -gr -k2:



4.5 5.6e-16
5.0 3.4e-18
6.7 2.3e-12
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


This is the output of locale:



LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC=de_DE.utf8
LC_TIME=de_DE.utf8
LC_COLLATE="en_US.utf8"
LC_MONETARY=de_DE.utf8
LC_MESSAGES="en_US.utf8"
LC_PAPER=de_DE.utf8
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT=de_DE.utf8
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=


Any suggestions and help are highly appreciated! Thanks!










share|improve this question









New contributor




Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • None of the "failed sorted" is in the example input file. What do you get if you sort the example set of data you've shown us? What do you expect to get? Are the columns separated by a tab or by (multiple) spaces?

    – roaima
    2 days ago













  • Is the question supposed to show the input and corresponding output? The data do not match. If you ran the command on a big file and copied parts of the data only, you should instead create a smaller input file and show the expected and actual output for this input.

    – Bodo
    2 days ago








  • 1





    What is the output of locale? (Please add it to your question.) I'm expecting to find that it's one that ignores the - character.

    – roaima
    2 days ago













  • here is the locale output: LANG=en_US.utf8 LC_CTYPE="en_US.utf8" LC_NUMERIC=de_DE.utf8 LC_TIME=de_DE.utf8 LC_COLLATE="en_US.utf8" LC_MONETARY=de_DE.utf8 LC_MESSAGES="en_US.utf8" LC_PAPER=de_DE.utf8 LC_NAME="en_US.utf8" LC_ADDRESS="en_US.utf8" LC_TELEPHONE="en_US.utf8" LC_MEASUREMENT=de_DE.utf8 LC_IDENTIFICATION="en_US.utf8" LC_ALL=

    – Lukas Fuchs
    2 days ago













  • The columns are tab separated

    – Lukas Fuchs
    2 days ago














5












5








5








I am trying to sort a data file in descending order. The data file is given by three columns and I want to order them in descending order for the third column with (the third column is given as a scientific notation in exponential value):



cat eII_surf.txt | sort -gr -k3


Somehow, this worked on a previous machine, but my new one does not seem to do the trick at all.



Here a simple example:



cat test.txt:



6.7 2.3e-12
5.0 3.4e-18
4.5 5.6e-16
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


and cat test.txt | sort -gr -k2:



4.5 5.6e-16
5.0 3.4e-18
6.7 2.3e-12
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


This is the output of locale:



LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC=de_DE.utf8
LC_TIME=de_DE.utf8
LC_COLLATE="en_US.utf8"
LC_MONETARY=de_DE.utf8
LC_MESSAGES="en_US.utf8"
LC_PAPER=de_DE.utf8
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT=de_DE.utf8
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=


Any suggestions and help are highly appreciated! Thanks!










share|improve this question









New contributor




Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am trying to sort a data file in descending order. The data file is given by three columns and I want to order them in descending order for the third column with (the third column is given as a scientific notation in exponential value):



cat eII_surf.txt | sort -gr -k3


Somehow, this worked on a previous machine, but my new one does not seem to do the trick at all.



Here a simple example:



cat test.txt:



6.7 2.3e-12
5.0 3.4e-18
4.5 5.6e-16
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


and cat test.txt | sort -gr -k2:



4.5 5.6e-16
5.0 3.4e-18
6.7 2.3e-12
4.2 2.1e-15
4.0 2.9e-17
2.4 2.5e-15
1.0 1.0e-17
0.5 1.0e-18


This is the output of locale:



LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC=de_DE.utf8
LC_TIME=de_DE.utf8
LC_COLLATE="en_US.utf8"
LC_MONETARY=de_DE.utf8
LC_MESSAGES="en_US.utf8"
LC_PAPER=de_DE.utf8
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT=de_DE.utf8
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=


Any suggestions and help are highly appreciated! Thanks!







sort locale






share|improve this question









New contributor




Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Stéphane Chazelas

310k57586945




310k57586945






New contributor




Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Lukas FuchsLukas Fuchs

283




283




New contributor




Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Lukas Fuchs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • None of the "failed sorted" is in the example input file. What do you get if you sort the example set of data you've shown us? What do you expect to get? Are the columns separated by a tab or by (multiple) spaces?

    – roaima
    2 days ago













  • Is the question supposed to show the input and corresponding output? The data do not match. If you ran the command on a big file and copied parts of the data only, you should instead create a smaller input file and show the expected and actual output for this input.

    – Bodo
    2 days ago








  • 1





    What is the output of locale? (Please add it to your question.) I'm expecting to find that it's one that ignores the - character.

    – roaima
    2 days ago













  • here is the locale output: LANG=en_US.utf8 LC_CTYPE="en_US.utf8" LC_NUMERIC=de_DE.utf8 LC_TIME=de_DE.utf8 LC_COLLATE="en_US.utf8" LC_MONETARY=de_DE.utf8 LC_MESSAGES="en_US.utf8" LC_PAPER=de_DE.utf8 LC_NAME="en_US.utf8" LC_ADDRESS="en_US.utf8" LC_TELEPHONE="en_US.utf8" LC_MEASUREMENT=de_DE.utf8 LC_IDENTIFICATION="en_US.utf8" LC_ALL=

    – Lukas Fuchs
    2 days ago













  • The columns are tab separated

    – Lukas Fuchs
    2 days ago



















  • None of the "failed sorted" is in the example input file. What do you get if you sort the example set of data you've shown us? What do you expect to get? Are the columns separated by a tab or by (multiple) spaces?

    – roaima
    2 days ago













  • Is the question supposed to show the input and corresponding output? The data do not match. If you ran the command on a big file and copied parts of the data only, you should instead create a smaller input file and show the expected and actual output for this input.

    – Bodo
    2 days ago








  • 1





    What is the output of locale? (Please add it to your question.) I'm expecting to find that it's one that ignores the - character.

    – roaima
    2 days ago













  • here is the locale output: LANG=en_US.utf8 LC_CTYPE="en_US.utf8" LC_NUMERIC=de_DE.utf8 LC_TIME=de_DE.utf8 LC_COLLATE="en_US.utf8" LC_MONETARY=de_DE.utf8 LC_MESSAGES="en_US.utf8" LC_PAPER=de_DE.utf8 LC_NAME="en_US.utf8" LC_ADDRESS="en_US.utf8" LC_TELEPHONE="en_US.utf8" LC_MEASUREMENT=de_DE.utf8 LC_IDENTIFICATION="en_US.utf8" LC_ALL=

    – Lukas Fuchs
    2 days ago













  • The columns are tab separated

    – Lukas Fuchs
    2 days ago

















None of the "failed sorted" is in the example input file. What do you get if you sort the example set of data you've shown us? What do you expect to get? Are the columns separated by a tab or by (multiple) spaces?

– roaima
2 days ago







None of the "failed sorted" is in the example input file. What do you get if you sort the example set of data you've shown us? What do you expect to get? Are the columns separated by a tab or by (multiple) spaces?

– roaima
2 days ago















Is the question supposed to show the input and corresponding output? The data do not match. If you ran the command on a big file and copied parts of the data only, you should instead create a smaller input file and show the expected and actual output for this input.

– Bodo
2 days ago







Is the question supposed to show the input and corresponding output? The data do not match. If you ran the command on a big file and copied parts of the data only, you should instead create a smaller input file and show the expected and actual output for this input.

– Bodo
2 days ago






1




1





What is the output of locale? (Please add it to your question.) I'm expecting to find that it's one that ignores the - character.

– roaima
2 days ago







What is the output of locale? (Please add it to your question.) I'm expecting to find that it's one that ignores the - character.

– roaima
2 days ago















here is the locale output: LANG=en_US.utf8 LC_CTYPE="en_US.utf8" LC_NUMERIC=de_DE.utf8 LC_TIME=de_DE.utf8 LC_COLLATE="en_US.utf8" LC_MONETARY=de_DE.utf8 LC_MESSAGES="en_US.utf8" LC_PAPER=de_DE.utf8 LC_NAME="en_US.utf8" LC_ADDRESS="en_US.utf8" LC_TELEPHONE="en_US.utf8" LC_MEASUREMENT=de_DE.utf8 LC_IDENTIFICATION="en_US.utf8" LC_ALL=

– Lukas Fuchs
2 days ago







here is the locale output: LANG=en_US.utf8 LC_CTYPE="en_US.utf8" LC_NUMERIC=de_DE.utf8 LC_TIME=de_DE.utf8 LC_COLLATE="en_US.utf8" LC_MONETARY=de_DE.utf8 LC_MESSAGES="en_US.utf8" LC_PAPER=de_DE.utf8 LC_NAME="en_US.utf8" LC_ADDRESS="en_US.utf8" LC_TELEPHONE="en_US.utf8" LC_MEASUREMENT=de_DE.utf8 LC_IDENTIFICATION="en_US.utf8" LC_ALL=

– Lukas Fuchs
2 days ago















The columns are tab separated

– Lukas Fuchs
2 days ago





The columns are tab separated

– Lukas Fuchs
2 days ago










1 Answer
1






active

oldest

votes


















9














2.3e-12 would be understood as 2 in a locale where the decimal radix character is , (as it is in most of the non-English speaking world including your de_DE.utf8) where the number would need to be written 2,3e-12.



You could do:



LC_ALL=C sort -grk2 < your-file


To force numbers being interpreted in the English style.



In the C locale (the only one you would be guaranteed to find on any system), the decimal radix is . (conveniently for your input).



Note that sort has nothing to do with bash, it's a separate command. The -g option is a non-standard extension of the GNU implementation of sort.






share|improve this answer





















  • 2





    Thanks! That one seems to work. Would you recommend to set up LC_ALL=C in the bashrc as a new environment variable?

    – Lukas Fuchs
    2 days ago






  • 3





    @LukasFuchs, no I wouldn't. You'd want to use LC_ALL=C only for commands where you don't want the behaviour to be affected by the user's localisation preferences. See What does "LC_ALL=C" do?

    – Stéphane Chazelas
    2 days ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Lukas Fuchs is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506965%2fbash-sort-g-does-not-work-properly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














2.3e-12 would be understood as 2 in a locale where the decimal radix character is , (as it is in most of the non-English speaking world including your de_DE.utf8) where the number would need to be written 2,3e-12.



You could do:



LC_ALL=C sort -grk2 < your-file


To force numbers being interpreted in the English style.



In the C locale (the only one you would be guaranteed to find on any system), the decimal radix is . (conveniently for your input).



Note that sort has nothing to do with bash, it's a separate command. The -g option is a non-standard extension of the GNU implementation of sort.






share|improve this answer





















  • 2





    Thanks! That one seems to work. Would you recommend to set up LC_ALL=C in the bashrc as a new environment variable?

    – Lukas Fuchs
    2 days ago






  • 3





    @LukasFuchs, no I wouldn't. You'd want to use LC_ALL=C only for commands where you don't want the behaviour to be affected by the user's localisation preferences. See What does "LC_ALL=C" do?

    – Stéphane Chazelas
    2 days ago


















9














2.3e-12 would be understood as 2 in a locale where the decimal radix character is , (as it is in most of the non-English speaking world including your de_DE.utf8) where the number would need to be written 2,3e-12.



You could do:



LC_ALL=C sort -grk2 < your-file


To force numbers being interpreted in the English style.



In the C locale (the only one you would be guaranteed to find on any system), the decimal radix is . (conveniently for your input).



Note that sort has nothing to do with bash, it's a separate command. The -g option is a non-standard extension of the GNU implementation of sort.






share|improve this answer





















  • 2





    Thanks! That one seems to work. Would you recommend to set up LC_ALL=C in the bashrc as a new environment variable?

    – Lukas Fuchs
    2 days ago






  • 3





    @LukasFuchs, no I wouldn't. You'd want to use LC_ALL=C only for commands where you don't want the behaviour to be affected by the user's localisation preferences. See What does "LC_ALL=C" do?

    – Stéphane Chazelas
    2 days ago
















9












9








9







2.3e-12 would be understood as 2 in a locale where the decimal radix character is , (as it is in most of the non-English speaking world including your de_DE.utf8) where the number would need to be written 2,3e-12.



You could do:



LC_ALL=C sort -grk2 < your-file


To force numbers being interpreted in the English style.



In the C locale (the only one you would be guaranteed to find on any system), the decimal radix is . (conveniently for your input).



Note that sort has nothing to do with bash, it's a separate command. The -g option is a non-standard extension of the GNU implementation of sort.






share|improve this answer















2.3e-12 would be understood as 2 in a locale where the decimal radix character is , (as it is in most of the non-English speaking world including your de_DE.utf8) where the number would need to be written 2,3e-12.



You could do:



LC_ALL=C sort -grk2 < your-file


To force numbers being interpreted in the English style.



In the C locale (the only one you would be guaranteed to find on any system), the decimal radix is . (conveniently for your input).



Note that sort has nothing to do with bash, it's a separate command. The -g option is a non-standard extension of the GNU implementation of sort.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









Stéphane ChazelasStéphane Chazelas

310k57586945




310k57586945








  • 2





    Thanks! That one seems to work. Would you recommend to set up LC_ALL=C in the bashrc as a new environment variable?

    – Lukas Fuchs
    2 days ago






  • 3





    @LukasFuchs, no I wouldn't. You'd want to use LC_ALL=C only for commands where you don't want the behaviour to be affected by the user's localisation preferences. See What does "LC_ALL=C" do?

    – Stéphane Chazelas
    2 days ago
















  • 2





    Thanks! That one seems to work. Would you recommend to set up LC_ALL=C in the bashrc as a new environment variable?

    – Lukas Fuchs
    2 days ago






  • 3





    @LukasFuchs, no I wouldn't. You'd want to use LC_ALL=C only for commands where you don't want the behaviour to be affected by the user's localisation preferences. See What does "LC_ALL=C" do?

    – Stéphane Chazelas
    2 days ago










2




2





Thanks! That one seems to work. Would you recommend to set up LC_ALL=C in the bashrc as a new environment variable?

– Lukas Fuchs
2 days ago





Thanks! That one seems to work. Would you recommend to set up LC_ALL=C in the bashrc as a new environment variable?

– Lukas Fuchs
2 days ago




3




3





@LukasFuchs, no I wouldn't. You'd want to use LC_ALL=C only for commands where you don't want the behaviour to be affected by the user's localisation preferences. See What does "LC_ALL=C" do?

– Stéphane Chazelas
2 days ago







@LukasFuchs, no I wouldn't. You'd want to use LC_ALL=C only for commands where you don't want the behaviour to be affected by the user's localisation preferences. See What does "LC_ALL=C" do?

– Stéphane Chazelas
2 days ago












Lukas Fuchs is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Lukas Fuchs is a new contributor. Be nice, and check out our Code of Conduct.













Lukas Fuchs is a new contributor. Be nice, and check out our Code of Conduct.












Lukas Fuchs is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506965%2fbash-sort-g-does-not-work-properly%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...