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

标签 linux unix sorting csv

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

/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/

相关文章:

linux - 为什么计划策略和参数的设置在我的程序 - pthread Linux 中失败?

javascript - 按百分比从数字数组中抽取

ios - 使用 Swift 在 UITableview 中对 Backendless 数据进行分组和排序

linux - 在密码文件linux中排序

c - 从 C 程序调用 GCC 时抑制错误输出

html - 在 bash 中使用脚本获取列表框的值

linux - `sed: -e expression #1, char 1: unknown command: ` , '`

bash - 在别名中使用管道

c - 如何在障碍处正确同步线程

linux - 如何在 UNIX 中读取一个值