我需要对输出进行排序:
/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
基于日期的年份,如“050112004”,即“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/