2013-05-05 41 views
0

我需要這個排序輸出:的Unix - 排序特定輸出

/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 

感謝

回答

1

您可以使用sed提取排序鍵,行排序,並刪除與cut排序關鍵字:

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

它的工作原理謝謝 – Frank 2013-05-05 16:46:11

1

使用-k選項進行分類:

sort -t '/' -k5.11