gpt4 book ai didi

bash - 在 shell 脚本中对多个非标准列进行排序

转载 作者:行者123 更新时间:2023-12-04 04:56:09 25 4
gpt4 key购买 nike

我有一个包含完整路径的文件列表,我需要在 bash shell 中对其进行排序。

列表看起来像

/total/path/software/version1.2.3.4/filename.10.cfg -- infomation grepped
/full/path/software/version1.2.3.4/filename.1.cfg -- infomation grepped
/long/path/software/version1.2.3.4/filename.2.cfg -- infomation grepped
/full/path/software/version1.2.3.4/filename.12.cfg -- infomation grepped
/long/path/software/version1.2.3.4/filename.1.cfg -- infomation grepped
/full/path/software/version1.2.3.4/filename.3.cfg -- infomation grepped
/long/path/software/version1.2.3.4/filename.18.cfg -- infomation grepped
/full/path/software/version1.2.3.4/filename.20.cfg -- infomation grepped
/real/path/software/version1.2.3.4/filename.4.cfg -- infomation grepped
/total/path/software/version1.2.3.4/filename.5.cfg -- infomation grepped

我需要首先按路径排序列表,然后按文件名编号。

我试过:
 sort -t'.' -k 1,1 -k 2,5n fileame.txt

但它只按路径排序。如果我这样做:
sort -t'.' -k5n filename.txt

它工作正常。按路径排序后,如何按数字顺序获取文件名?

谢谢

最佳答案

您需要排序到filename首先然后指定 filename数字作为决胜局

sort -t'.' -k1,4 -k5n,5n filename.txt
/full/path/software/version1.2.3.4/filename.1.cfg -- infomation grepped
/full/path/software/version1.2.3.4/filename.3.cfg -- infomation grepped
/full/path/software/version1.2.3.4/filename.12.cfg -- infomation grepped
/full/path/software/version1.2.3.4/filename.20.cfg -- infomation grepped
/long/path/software/version1.2.3.4/filename.1.cfg -- infomation grepped
/long/path/software/version1.2.3.4/filename.2.cfg -- infomation grepped
/long/path/software/version1.2.3.4/filename.18.cfg -- infomation grepped
/real/path/software/version1.2.3.4/filename.4.cfg -- infomation grepped
/total/path/software/version1.2.3.4/filename.5.cfg -- infomation grepped
/total/path/software/version1.2.3.4/filename.10.cfg -- infomation grepped

关于bash - 在 shell 脚本中对多个非标准列进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16724800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com