Linux sort P-values with scientific notation
2
2
Entering edit mode
5.1 years ago
Shicheng Guo ★ 9.6k

Hi All,

I want to sort P-values in bash with sort command. The P-values are as the following:

A    1.14e-06
B    4.35e-05
C    0.5361
D    0.7278

When you use sort -k2n,2 input.txt, the result is as the following:

C    0.5361
D    0.7278
A    1.14e-06
B    4.35e-05

I tried sort -gk2n,2 input.txt and not working neither.

Anyone can share a correct bash or Perl one-line command to sort them correctly.

Thanks.

sort pvalue scientific notation • 3.0k views
ADD COMMENT
3
Entering edit mode
5.1 years ago
JC 13k
$ sort -g -k2 list
A    1.14e-06
B    4.35e-05
C    0.5361
D    0.7278
ADD COMMENT
0
Entering edit mode

interesting. remove n numeric works. and works very well

ADD REPLY
0
Entering edit mode
5.1 years ago
zx8754 12k

Using both g and n at the same time gives an error:

$ sort -gn input.txt
sort: options '-gn' are incompatible

Or:

$ sort -k2ng,2 input.txt
sort: options '-gn' are incompatible

I am guessing, in your case it doesn't throw an error as we are using g for all columns and n for the second column.

ADD COMMENT

Login before adding your answer.

Traffic: 1639 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6