0

I need to sort this output:

/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

Based on the year of the date like this "05012004" that would be "ggmmyyyy" so based on "yyyy".

So in the following way it's sorted:

/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

Thanks

4

2 回答 2

1

您可以使用sed以下命令提取排序键、对行进行排序并删除排序键cut

sed -e 's/^.*[0-9]\{4\}\([0-9]\{4\}\)/\1,&/' |
sort |
cut -d, -f2-
于 2013-05-05T15:26:23.003 回答
1

使用 -k 选项进行排序:

sort -t '/' -k5.11
于 2013-05-05T15:30:21.863 回答