bash sort -g does not work properly
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
New contributor
add a comment |
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
New contributor
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
Mar 18 at 11:49
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
Mar 18 at 11:52
1
What is the output oflocale
? (Please add it to your question.) I'm expecting to find that it's one that ignores the-
character.
– roaima
Mar 18 at 11:53
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
Mar 18 at 12:45
The columns are tab separated
– Lukas Fuchs
Mar 18 at 12:46
add a comment |
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
New contributor
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
sort locale
New contributor
New contributor
edited Mar 18 at 13:20
Stéphane Chazelas
311k57586945
311k57586945
New contributor
asked Mar 18 at 11:23
Lukas FuchsLukas Fuchs
283
283
New contributor
New contributor
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
Mar 18 at 11:49
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
Mar 18 at 11:52
1
What is the output oflocale
? (Please add it to your question.) I'm expecting to find that it's one that ignores the-
character.
– roaima
Mar 18 at 11:53
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
Mar 18 at 12:45
The columns are tab separated
– Lukas Fuchs
Mar 18 at 12:46
add a comment |
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
Mar 18 at 11:49
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
Mar 18 at 11:52
1
What is the output oflocale
? (Please add it to your question.) I'm expecting to find that it's one that ignores the-
character.
– roaima
Mar 18 at 11:53
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
Mar 18 at 12:45
The columns are tab separated
– Lukas Fuchs
Mar 18 at 12:46
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
Mar 18 at 11:49
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
Mar 18 at 11:49
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
Mar 18 at 11:52
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
Mar 18 at 11:52
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
Mar 18 at 11:53
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
Mar 18 at 11:53
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
Mar 18 at 12:45
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
Mar 18 at 12:45
The columns are tab separated
– Lukas Fuchs
Mar 18 at 12:46
The columns are tab separated
– Lukas Fuchs
Mar 18 at 12:46
add a comment |
1 Answer
1
active
oldest
votes
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
.
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
Mar 18 at 13:05
3
@LukasFuchs, no I wouldn't. You'd want to useLC_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
Mar 18 at 13:08
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
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
Mar 18 at 13:05
3
@LukasFuchs, no I wouldn't. You'd want to useLC_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
Mar 18 at 13:08
add a comment |
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
.
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
Mar 18 at 13:05
3
@LukasFuchs, no I wouldn't. You'd want to useLC_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
Mar 18 at 13:08
add a comment |
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
.
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
.
edited Mar 18 at 13:22
answered Mar 18 at 13:02
Stéphane ChazelasStéphane Chazelas
311k57586945
311k57586945
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
Mar 18 at 13:05
3
@LukasFuchs, no I wouldn't. You'd want to useLC_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
Mar 18 at 13:08
add a comment |
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
Mar 18 at 13:05
3
@LukasFuchs, no I wouldn't. You'd want to useLC_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
Mar 18 at 13:08
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
Mar 18 at 13:05
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
Mar 18 at 13:05
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
Mar 18 at 13:08
@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
Mar 18 at 13:08
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
Mar 18 at 11:49
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
Mar 18 at 11:52
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
Mar 18 at 11:53
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
Mar 18 at 12:45
The columns are tab separated
– Lukas Fuchs
Mar 18 at 12:46