2013-05-05 3 views
0

Мне нужно сортировать этот вывод:Unix - Sort частности выход

/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» так, основанный на «гггг».

Таким образом, в следующем образом отсортирован:

/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

1

Используйте опцию -k с сортировкой:

sort -t '/' -k5.11 
Смежные вопросы