簡體   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