繁体   English   中英

linux中的sort命令无法正常工作

[英]The sort command in linux does not work “correctly”

我在Linux上工作, sort命令返回的不是预期的。

输入文本:

$ cat input.txt
rep1_1.fq
rep1_2.fq
rep12_1.fq
rep12_2.fq

命令和输出:

$ sort input.txt
rep1_1.fq
rep12_1.fq
rep12_2.fq
rep1_2.fq


$ sort --version
sort (GNU coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.

排序后,我预计rep1_2.fq将在rep1_1.fq之后,但结果是不同的。

解决了

根据@ Federico klez Culloca的建议,使用LC_ALL=C

$ LC_ALL=C sort input.txt
rep12_1.fq
rep12_2.fq
rep1_1.fq
rep1_2.fq

编辑

使用LC_ALL=C还修复目录中的排序文件。

如果当前目录中有四个文件:

$ LC_ALL= ls
rep1_1.fq  rep12_1.fq  rep12_2.fq  rep1_2.fq

$ LC_ALL=C ls
rep12_1.fq  rep12_2.fq  rep1_1.fq  rep1_2.fq

尝试使用version-sort 从手册:

       -V, --version-sort
          natural sort of (version) numbers within text

这是使用您的示例的输出:

$ sort -V input.txt 
rep1_1.fq
rep1_2.fq
rep12_1.fq
rep12_2.fq

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM