gpt4 book ai didi

linux - Unix - 对特定输出进行排序

转载 作者:太空宇宙 更新时间:2023-11-04 09:45:56 25 4
gpt4 key购买 nike

我需要对这个输出进行排序:

/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_04092008/es3.sml: some content .... with words and symbols
/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_05012004/es3.sml: some content .... with words and symbols
/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_24072010/es3.sml: some content .... with words and symbols
/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_05012004/es3.sml: some content .... with words and symbols

基于日期的年份,如“05012004”,将是“ggmmyyyy”,因此基于“yyyy”。

所以按以下方式排序:

/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_05012004/es3.sml: some content .... with words and symbols
/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_05012004/es3.sml: some content .... with words and symbols
/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_04092008/es3.sml: some content .... with words and symbols
/dir1NameWithSpaces/dir2NameWithSpaces/dir3NameWithSpaces/File1_24072010/es3.sml: some content .... with words and symbols

谢谢

最佳答案

您可以使用 sed 提取排序键,对行进行排序并使用 cut 删除排序键:

sed -e 's/^.*[0-9]\{4\}\([0-9]\{4\}\)/\1,&/' |
sort |
cut -d, -f2-

关于linux - Unix - 对特定输出进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16385977/

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